static members throught static methods
Given: 1. public class Base { 2. public static final String FOO = "foo";
3. public static void main(String[] args) { 4. Base b = new Base(); 5. Sub
s = new Sub(); 6. System.out.print(Base.FOO); 7.
System.out.print(Sub.FOO); 8. System.out.print(b.FOO); 9.
System.out.print(s.FOO); 10. System.out.print(((Base)s).FOO); 11. } } 12.
class Sub extends Base {public static final String FOO="bar";}
What is the result? A. foofoofoofoofoo B. foobarfoobarbar C.
foobarfoofoofoo D. foobarfoobarfoo E. barbarbarbarbar F. foofoofoobarbar
G. foofoofoobarfoo Answer: D
My doubt is that in line 8 and line we are using reference variables to
access static members of class..is it possible? because static members are
accessed by class names only..plz correct me where i am wrong?
No comments:
Post a Comment