A. x = 0 B. x = 23 C. compilations fail because of an error in line 2 of Test2. D. compilations fail because of an error in line 3 of Test1. E. compilations fail because of an error in line 4 of Test2.
my answer is C.
but my fren said that there is no wrong with line 2 of Test2 because Test2 can extends test1.Test1. instead he said that D is the answer because the line 3 of Test1 is the default acess, so from package test2 cant' access package test1's class's variable of x =23.
so any advice from senior here??? please help me....thanks.
Variable x is declared as public by default and therefore visible in class Test2. The main() method is a static method and therefore it is no problem to access the static variable x.
Andrew, the static variable x has the default access specifier i.e. non. This means that access is allowed inside the class and its package but not its subclasses. To be visible to subclasses in another package it would need to be protected or public.