This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes questions about Dan mock up exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "questions about Dan mock up exam" Watch "questions about Dan mock up exam" New topic
Author

questions about Dan mock up exam

emo wang
Greenhorn

Joined: Apr 02, 2004
Posts: 1
hi guys,
I have a question about Dan's mockup exam,
abstract class A { // 1
private abstract void m1(); // 2
private abstract class B {} // 3
private class C extends B {} // 4
}
Which line results in a compile-time error?
a. 1
b. 2
c. 3
d. 4
e. None of the above.
the solution is b, but I am so lost don't know why, would any of you explain to me?
thank you so much for help!
emo
Anil Hulikal
Greenhorn

Joined: Apr 02, 2004
Posts: 29
From Java Language Specifications
***
It is a compile-time error for a private method to be declared abstract.
It would be impossible for a subclass to implement a private abstract method, because private methods are not inherited by subclasses; therefore such a method could never be used.
***
Also, if you try to compile the program in a good IDE (like Netbeans), it clearly says
***
A.java [12:1] illegal combination of modifiers: abstract and private
private abstract void m1(); // 2
^
1 error
Errors compiling A.
***
Regards,
Anil


Just stay focused.
Anil Hulikal
Greenhorn

Joined: Apr 02, 2004
Posts: 29
From Java Language Specifications
***
It is a compile-time error for a private method to be declared abstract.
It would be impossible for a subclass to implement a private abstract method, because private methods are not inherited by subclasses; therefore such a method could never be used.
***
Also, if you try to compile the program in a good IDE (like Netbeans), it clearly says
***
A.java [12:1] illegal combination of modifiers: abstract and private
private abstract void m1(); // 2
^
1 error
Errors compiling A.
***
Regards,
Anil
Vineela Devi
Ranch Hand

Joined: Dec 20, 2003
Posts: 191
Hi Emo,
Ya. the complier complains at line 2 coz u cannot use both private and abstract modifiers together.
Reason is tht abstract methods are meant to be overridden .But private methods can never be overridden there by contracting each other.
Therefore, we should not use both private and abstract together for a method.
Regards
Vineela
fethi makhlouf
Ranch Hand

Joined: Feb 16, 2004
Posts: 50
Hi there
That's clear : we can never have a both private and abstract for any method! but what's ackward.....is that c:\ is true!
How can we really have an private abstract inner class?


SCJP 1.4
Suresh Thota
Ranch Hand

Joined: Sep 24, 2003
Posts: 152
Hi fethi,
private abstract is allowed for inner classe's because other inner class in the same enclosing class can extend this abstract class (inspite of being private) and provide implementation.
Hope am clear.
PS: actually I'm looking for a post I can answer, so that my status will be up to ranch hand.
Cheers
-Suresh


SCJP 1.6
sai kumar
Ranch Hand

Joined: Mar 31, 2004
Posts: 72
Hi Suresh,
I appreciate your confidence.
Can you please answer/clarify my question in the garbage collection thread.
Thx
sk
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: questions about Dan mock up exam
 
Similar Threads
Dan's Mock Test on Nested classes
a question about Dan's mock
can a method be private and abstract at the same time?
Question from Dan chisholm on abstract class
abstract