This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Mock Exam Errata and the fly likes Problem with tipsmart  q24 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Problem with tipsmart  q24" Watch "Problem with tipsmart  q24" New topic
Author

Problem with tipsmart q24

jordan gong
Ranch Hand

Joined: Jun 12, 2001
Posts: 37
I am not sure the following two statements are true?
q24.
(1) Each method in a parent class can be overridden at most once in any one subclass
(3) Overriding methods must return exactly the same type as the method they override
The answer indicates they are true, but I doubt about them. Please help.
jordan
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Jordan,
They are both true.
(1) When you override a method you have to use the same signature ; if you declare two methods with the same signature, in the same class, you get a compile error.
(3) One of the rules of overriding is that the overriding method must have the same return type. See JLS �8.4.6.3
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited June 20, 2001).]


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
jordan gong
Ranch Hand

Joined: Jun 12, 2001
Posts: 37
Thanks a lot!
What about 1)?
Can it overrides at most once?

Daniel Wu
Ranch Hand

Joined: Jun 13, 2001
Posts: 58
Jane,
How about static methods? I heard that static methods cannot be overriden by the subclass? Please clarify that. Thanks a lot.
Daniel
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Jordan,
A subclass can only override an instance method in the parent by creating one overriding method. Here's an example

1. this is a legal override of <code>method()</code> in <code>SuperA</code>. It has the same signature (method name and parameters) and the same return type.
2. produces a compile error, the previous method has the same signature, you cannot have two methods with the same signature in the same class.
3. produces a compile error, it is not legal for the same reason as (2) and it is not legal as an 'overload' because it does not have different parameters.
4 & 5 both overload the <code>method()</code> in <code>SubA</code>. They have the same name but different parameter lists. An overload method may also have a different return type.
Daniel,
'static' methods cannot be overridden as they are not instance methods; overriding only applies to instances.
See the Sun Tech Tip on Shadowing.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited June 23, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with tipsmart q24
 
Similar Threads
Null References
Mock Exam
null doubt
calling a method()
explain the answer