public static void main(String[] args){
int i = 123;
byte j = 127;
Overloading ol= new Overloading();
ol.M( i , j );
ol.M( j , i );
}
/** Here's the two overloaded
versions of M method */
void M(int i, byte j){
System.out.println(" int i is first, " + i + " and " + " byte
j is next, "+ j);
}
void M(byte j, int i){
System.out.println(" Here byte j is first, " + j + " and " +
" int i is second, "+ i);
}
}
Q1 Overloaded methods are distinguished by
the compiler in three ways. Name
the three ways
and state which the above two lines of code demonstrate.
Overriding Excercise
Peter Komisar
class P{
int Variable=7;
void M(){System.out.println(" P method version ");
}
}
class C extends P{
int Variable=11;
void M( ){System.out.println(" C method version ");
}
}
class OverRideTest{
public static void main(String[] args){
P pcmix=null;
P p=new P( );
C c=new C( );
pcmix=c;
// assigning child to parent type
p.M( );
c.M( );
pcmix.M( );
System.out.println(" Referencing parent object for it's variable, Variable
is " + p.Variable);
System.out.println(" Referencing child object for it's variable, Variable
is " + c.Variable);
System.out.println(" Referencing pcmix object for it's variable, Variable
is " + pcmix.Variable);
}
}
1) a) For parent object, p, which value of
variable is called(p or c)?
b) For child object, c,
which value of variable is called (p or c)?
c) For child assigned to
parent type variable, pcmix which value
of variable is called (p or c)?
2) a) For parent object, p, which version of
method is called(p or c)?
b) For child object, c,
which version of method is called(p or c?
c) For child assigned to
parent type variable, pcmix which version
of method
is called (p or c)?
3) What conclusion can you draw from
these results?