Your code is almost valid Perl 6. In order to inspect attribute $!x you have to construct an object instance leading to the two suggestions below. See the Perl 6 Object Orientation document for more.
The first approach is a more usual starting point for development.
class A {
has Str $.x ;
method test {
say 'Test';
say $!x ;
}
}
A.new(x =>'hello').test;
The second approach is more advanced but may be closer to the OP intentions.
class A {
has Str $.x ;
submethod TWEAK {
say 'Test';
say $!x ;
}
}
A.new;