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


Please Help Members By Posting Answers For Below Questions

What are the types of interface used in the java collections? : java collections

586


What is the use of hashcode in java ?

573


What is the Spring2.5 MVC Navigation flow?

5363


Hi Friends , am newbie to ajax. For example just consider one account registration - A form contains 8 text fields with submit button. In this form second texbox contains "username " . On right side of text box there is a label box . On clilck action i need to determine user is available or not. Is it possible on clicking label or should i click submit button.

1579


What do you understand by synchronization? Why is it important?

566






How do I find jre path in windows?

523


What are the different types of classes implemented in the set interfaces? : java collections

602


can u draw class/object diagram for ATM

5527


what is mean by hasing and maping in java platform and advantage?

1827


What is the use of the list interface in the java collection? : java collections

596


What are the different types of collections views being provided by the map interface? : java collections

613


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

1868


Which interface does java.util.hashtable implement?

667


What are the types of java collections? : java collections

537


What is deque in the java collections framework? : java collections

536