• Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt in Overriden Methods  RSS feed

 
Padma priya Gururajan
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class Test1{

public void method1(){
System.out.println("In Method1");
}


}

Class Test2 extends Test1{
public void method1(){
System.out.println("In Test2");
}


public void method2(){
System.out.println("In Test2");
}

public static void main(String args[]){
Test1 t1= new Test1();
Test2 t2=new Test1();
t1.method1();
t2.method2();
}

}


Could you please tell me as to what the output of
t2.method2() would be?
 
Chan Ag
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Padma priya Gururajan wrote:

Could you please tell me as to what the output of
t2.method2() would be?


Do you have JDK installed on your computer? How about you compile it and run it and see what output you get?

Please use code tags while posting code of any length. It makes your code easier to read.

Chan.
 
Ravi Khadgi
Greenhorn
Posts: 20
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your expected output and what doubt do you have?
 
upanshu vaid
Ranch Hand
Posts: 83
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you compile the code there will the error in this line
Test2 t2=new Test1();
you can't have the reference variable of child class pointing to superclass object.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!