Hi all,
I wrote a class Point and a class SubPoint which extends the class Point (see the code below). Then I declared a variable sp of type SubPoint and I called sp.tell(). Could anyone tell me why the method speak() of the class SubPoint is invoked although I already call super.tell() within the methode tell() of SubPoint?
Thank you very much.
==========================================================
class Point {
public void speak(){
System.out.println("Point.speak()");
}
public void tell(){
System.out.println("Point.tell()");
speak();
}
}
class SubPoint extends Point{
public void speak(){
System.out.println("SubPoint.speak()");
}
public void tell(){
System.out.println("SubPoint.tell()");
super.tell();
}
}
public class Test{
public static void main(String[] args){
SubPoint sp = new SubPoint();
sp.tell();
}
}
I wrote a class Point and a class SubPoint which extends the class Point (see the code below). Then I declared a variable sp of type SubPoint and I called sp.tell(). Could anyone tell me why the method speak() of the class SubPoint is invoked although I already call super.tell() within the methode tell() of SubPoint?
Thank you very much.
==========================================================
class Point {
public void speak(){
System.out.println("Point.speak()");
}
public void tell(){
System.out.println("Point.tell()");
speak();
}
}
class SubPoint extends Point{
public void speak(){
System.out.println("SubPoint.speak()");
}
public void tell(){
System.out.println("SubPoint.tell()");
super.tell();
}
}
public class Test{
public static void main(String[] args){
SubPoint sp = new SubPoint();
sp.tell();
}
}