Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reg. Overriding : Valiveru's exam

 
Angela Narain
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Which of the following are true about overloading & overridding.
A.Overrided methods return different return types and
will be in different classes.
B.Overloaded methods supplement where as overridden
method replace the method it overrides.
C.Return type of overriden method must be identical to
return type of method it overrides.
D.Given a method
public void aMethod(int i,float f);
the method
public void aMethod(float f,int i);
is a possible overridden method.

I assume the correct answers are B, C
What is the exact meaning of supplement in answer B.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Angela!
The overloaded methods suplement because they have difernts parameters whereas overriden methos have the same parameters.
Hope thats help.
 
Gagan Indus
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i agree , only B & C are correct
A) Overrriden methods return same return-type
D) Given methods are ex of overloading , not overriding

Meaning of supplement in B is , tht most of the times overloaded methods Supplements/ADDS to the functionality of original methods , providing functionality based on da types of arguments
like we hav float amethod( int , float )
then two overloaded methods ;
float amethod( int i ) { amethod(i, 0.0f) ; }
float amethod( float f ) { amethod(0 , f ) ; }
are supplementing the original method
where as overriden methods mostly replaces the original declaration ( tho they can call original method wid super.method() )
I knw dat isnt very gud xplanation , but somehow i ran outta words on dis
anybdy else , ur opinions plzz

------------------
Gagan (/^_^\)
 
Asma Zafar
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
supplement means enhance the functionality.
e.g. you have the following methods:

public void print(String s){
System.out.prinln(s);
}
public void print(int i){
System.out.prinln(i);
}
public void print(float f){
System.out.prinln(f);
}
These 3 methods are all printing, but in each method they are printing a different thing. Basically in overlaoding the method name is the same, but parameter list is different.
Hope this helps,

------------------
Asma Zafar,
Sun Certified Programmer for Java2 Platform
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic