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
Hi frnds how to lock an user when he enter wrong credentials more than 3 time using java or j2ee tech take username and password in a bean no need to connect DB and validate give me some sample application code or links its urgent for me thanks in advance
What are the different types of features of the java collections framework? : java collections
What are the interfaces in java collections? : java collections
What are the main classes of the list interfaces? : java collections
What is iterator in the java collections framework? : java collections
what is mean by hasing and maping in java platform and advantage?
please mail me the interview question based on java/j2ee
What are the queues in the java collection framework? : java collections
can u draw class/object diagram for ATM
Hi we have an urgent requirement for Java/J2ee technical lead position & also looking for "Java Guidewire claimcentre" experienced professional for Bangalore location if interested can reach srisanh@gmail.com
What is the difference between comparable and comparator in java.util pkg?
Which sorting algorithm is used by collections.sort() in java ?
What do you understand by synchronization? Why is it important?
What are the different types of collections views being provided by the map interface? : java collections
What are the types of the main implementing classes in the map interfaces? : java collections