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 / surendra

in main() create an object to derived class and call m1() by using this obj since all super class members are available to
subclass object.
Derived d=new Derived();
d.m1();

Is This Answer Correct ?    1 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the uses of the set interfaces in the java collections? : java collections

747


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

2742


What are the differences between the java collection and the java list? : java collections

800


What are the types of the main implementing classes in the map interfaces? : java collections

836


What is the difference between comparable and comparator in java.util pkg?

810


Which java collection class can be used to maintain the entries in the order in which they were last accessed?

765


What is java collection? : java collections

809


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

726


HOW MUCH PERCENTAGE WE DEDUCT FOR OUR SUPPLIERS OR OTHER PROFESSIONALS

1752


What is the use of hashcode in java ?

792


Hi Friends, i have searched in google but not clear. can you give bank example with synchronized keyword

1804


please mail me the interview question based on java/j2ee

1720


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

786


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

2084


What are the different types of ways where you can iterate over a list? : java collections

749