GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Placement Papers  >  Oracle  >  Java
Go To First  |  Previous Question  |  Next Question 
 Java  |  Question 49 of 134    Print  
Class A{
Public void meth(){
}
}

class B extends A{
Public void meth(){
}
public static void main(String args[]){
A a=new A();
a.meth();//which method will this call
}
}

if u want to call a method of class B then how can u achieve this?


  
Total Answers and Comments: 3 Last Update: April 15, 2006   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
June 19, 2005 02:15:33   #1  
chandra        

RE: Class A{Public void meth(){}}class B extends A{ Public void meth(){ } public static void main(Str...
public static void main(String args[]){ 
A a=new B(); 
a.meth();//which method will this call 
}  
}

 
Is this answer useful? Yes | No
October 25, 2005 13:35:11   #2  
sarala        

RE: Class A{Public void meth(){}}class ...

The following method ,creating the object of B that refers to A will call the meth() in Class B.

Question: Class A{
Public void meth(){
}
}

class B extends A{
Public void meth(){
}
public static void main(String args[]){
A a=new B();
a.meth();
}
}

Whenever a subclass needs to refer to its immediate superclass, it can do so by use of the keyword ‘super’ .


 
Is this answer useful? Yes | No
April 15, 2006 02:04:08   #3  
Ankur        

RE: Class A{Public void meth(){}}class ...

No if you want to really call a method in Derived Class then it is only possible if that method will only be present in Derived Class otherwise you can create direct object of the Derived Class.


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape