In reply to mlsxdx:
I think oyu are confusing overwriting the initial value with adding a new class variable. Your class B adds another variable called “name” that is only visible in the extended class. That is why you needed virtual method get_name in the extended class to access it. What you could do is overwrite name in the extended constructor.
class A;
string name = "A";
virtual function void print_it();
$display("name:%s",name);
endfunction
endclass
class B extends A;
function new;
name = "B";
endfunction
endclass