aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Methods and variables ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Methods and variables !" Watch "Methods and variables !" New topic
Author

Methods and variables !

anurag dwivedi
Greenhorn

Joined: May 18, 2001
Posts: 22
39. Which of the following statements are true?
A) An inner class cannot be defined as private.
B) Static methods can be overridden by static methods only.
C) Static variables can be called using class name.
D) Non static variables can be called using class name.
Ans : C
Why not B and D ?
Thanks,
Anurag


Sun Certified Programmer for the Java 2 Platform.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
B is false since static methods cannot be overridden but merely HIDDEN by a static method in a subclass
D is false too, the result of trying to access an instance variable using the class name will give the compile-time error :
"Can't make a static reference to nonstatic variable i in class Test."

However you could access i with the class name inside an instance method but using the "this" reference like this:

This works and yields
t.i=0
Test.this.i=0
But I don't see how it would be useful and why we would access i like that in an instance method !!
HIH Val
[This message has been edited by Valentin Crettaz (edited September 19, 2001).]
[This message has been edited by Valentin Crettaz (edited September 19, 2001).]


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
jQuery in Action, 2nd edition
 
subject: Methods and variables !