In reply to Sai Raghavendran :
I think you meant to write
function void copy(base x);
A abc; // abc is a friend to A
if ($cast(abc, x))
valid = abc.valid;
endfunction
This is safe because you are inside class A referencing a class variable abc whose type is also A. In OOP this is called a friendly access to another to a local or protected members of another class object. Other languages have an explicit keyword friend to allow this kind of access, but in SystemVerilog an object is always a friend to another object of the same class type.