How to call the m1() method of Base class in below snippet ?
class Base
{
public void m1()
{
System.out.println("Base m1 ");
}
public void m2()
{
System.out.println("Base m1 ");
}
}
======================
class Derived extends Base
{
public void m1()
{
System.out.println("Derived m1");
}
public void m3()
{
System.out.println("Derived m3");
}
public static void main(String[] args)
{
Base ob=new Derived();
ob.m1();
//System.out.println("Hello
World!"+ob.m1());
}
}
Answer Posted / kishore
Nand asking in the about snippet is saying like: The base class is referenced to derived class object (i.e Polymorphism). As a polymorphism point of view only overidden methods of Derived class will be called. But how is it possible to access the m1() of Base class using the reference of Base Class ?
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
How is hashset maintained in memory by java ?
Hi Friends, i have searched in google but not clear. can you give bank example with synchronized keyword
In hyderabad, which s/w training center is best for java, other than corejava what r the new tools to learn in java,which tool is best & have current requirement,pls give me information about java to learn ?
What are the types of java collections? : java collections
What are the differences between the java collection and the java list? : java collections
HOW MUCH PERCENTAGE WE DEDUCT FOR OUR SUPPLIERS OR OTHER PROFESSIONALS
What is iterator in the java collections framework? : java collections
What is an algorithm in java collection framework? : java collections
What is the enumerator of the java collection framework? : java collections
What is java collection? : java collections
Which interface does java.util.hashtable implement?
How do I find jre path in windows?
What are the types of the main implementing classes in the map interfaces? : java collections
What are the different types of classes implemented in the set interfaces? : java collections
please mail me the interview question based on java/j2ee