aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overridden Method in 1.5 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 "Overridden Method in 1.5" Watch "Overridden Method in 1.5" New topic
Author

Overridden Method in 1.5

Mvvsatyanarayana Murty
Greenhorn

Joined: May 19, 2009
Posts: 16
Which of the following statements are true?

1) A method cannot be overloaded to be less public in a child class
2) To be overridden a method only needs the same name and parameter types
3) To be overridden a method must have the same name, parameter and return types
4) An overridden method must have the same name, parameter names and parameter types

As of Java 1.4 the Answer is 3 (To be overridden a method must have the same name, parameter and return types). But in 1.5 the return type may be a different (Ex: SubClass return type ...) So Can I know the which answer i need to go?
Ryan Anderson
Greenhorn

Joined: May 18, 2009
Posts: 21
1 and 2 are true

But the return value must be either

a) same exact thing for primitives
b) subclass of the return type if its an object
c) implementing class of the return type if its an interface

Note: if you change the param types --> automatically an overload

This wont compile right away --> notice the Honda subclass where it tries to return a byte instead of int

Bob Wheeler
Ranch Hand

Joined: Apr 24, 2009
Posts: 317
Mvvsatyanarayana Murty wrote:
1) A method cannot be overloaded to be less public in a child class

Why is this true? For overriddin methods that's true, but for overloading? Actually I don't understand what this means. If this is not a typo, can anybody explains this to me? As far as I know, overloading only occur in one class, not in its child class.

cheers
Bob


SCJP 6 - SCJD - SCWCD 5 - SCBCD 5
JavaEnterpriseEditionFaq - TomcatFaq
Amirr Rafique
Ranch Hand

Joined: Nov 14, 2005
Posts: 324
Mvvsatyanarayana Murty wrote:Which of the following statements are true?

1) A method cannot be overloaded to be less public in a child class
2) To be overridden a method only needs the same name and parameter types
3) To be overridden a method must have the same name, parameter and return types
4) An overridden method must have the same name, parameter names and parameter types


The 4 is the correct answer.

So Can I know the which answer i need to go?


You can decide it from the version of SCJP exam. As the exam is different for Jave 1.4, 1.5 and 1.6


"Know where to find the solution and how to use it - that's the secret of success."
Amirr Rafique
Ranch Hand

Joined: Nov 14, 2005
Posts: 324
Bob Wheeler wrote:

overloading only occur in one class, not in its child class.

Bob


Method can also be overloaded in child class.

Hope it helps
Bob Wheeler
Ranch Hand

Joined: Apr 24, 2009
Posts: 317
Thanks Amirr. I forgot about the inheritance part
But I disagree with you about anwer 4. Overridding has nothing to do with parameter names. It's all about the argument list (types), the method name and the return type (same or subtype). So it's tricky. Answer 2 is wrong because it also needs the return type for overriding. But answer 3 is too strickt, because it says it must be the same return type. But it's the closest, so I'll go for answer 3.
Answer 1 is wrong because overloading doesn't care about access modifier.

cheers
Bob
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overridden Method in 1.5