File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Reg. Inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Reg. Inner class " Watch "Reg. Inner class " New topic
Author

Reg. Inner class

Angela Narain
Ranch Hand

Joined: Apr 14, 2001
Posts: 327
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.
The correct answer given is C
But i think it should be B, C
Am i right ?
Cristian Negresco
Ranch Hand

Joined: Sep 15, 2001
Posts: 182
It is me again,
I don't think B is good, why should it be?
Angela Narain
Ranch Hand

Joined: Apr 14, 2001
Posts: 327
Just try the following , you will get compile time error :

Change the line //1 to
public static void m() and the code will compile fine,
which should justify Ans. B as posted.

[This message has been edited by Angela Narain (edited September 25, 2001).]
Cristian Negresco
Ranch Hand

Joined: Sep 15, 2001
Posts: 182
Right...
Richard Barnes
Greenhorn

Joined: May 17, 2001
Posts: 6
Hi,
The question is deliberately confusing. When you implement an identical static method in a subclass (as in your code example above), it isn't termed overridding as it would be with a non-static method.
Both methods exist at the same time (whether or not there is an instance of a class) and only an object name qualifies which one you are referring to (otherwise in the subclass it will refer to its local method).
In other words, its not the fact that you can't implement it, its the fact that it is not called overridding in such a case.
Hope that helps.
Richard
Angela Narain
Ranch Hand

Joined: Apr 14, 2001
Posts: 327
Okay i agree that it is not termed as overriding w.r.t to
static methods but method hiding.
But if i go with the compilation error which is :

m() in Example cannot override m() in Super; overridden method is static

Suppose the statement was as follows :
Method in subclass cannot override static method of base class.
Would it be correct ?
Richard Barnes
Greenhorn

Joined: May 17, 2001
Posts: 6
Indeed it would, but its probably simpler just to say 'Static methods cannot be overridden'.
These were the sort of questions that really caught me out in the exam!
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Angela,
'Overriding' only relates to instances. A static method belongs to the class.
See this Tech Tip at Sun for an explanation.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reg. Inner class