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
What are the uses of the set interfaces in the java collections? : java collections
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 are the differences between the java collection and the java list? : java collections
What are the types of the main implementing classes in the map interfaces? : java collections
What is the difference between comparable and comparator in java.util pkg?
Which java collection class can be used to maintain the entries in the order in which they were last accessed?
What is java collection? : java collections
What is deque in the java collections framework? : java collections
HOW MUCH PERCENTAGE WE DEDUCT FOR OUR SUPPLIERS OR OTHER PROFESSIONALS
What is the use of hashcode in java ?
Hi Friends, i have searched in google but not clear. can you give bank example with synchronized keyword
please mail me the interview question based on java/j2ee
What is the use of the list interface in the java collection? : java collections
what is mean by hasing and maping in java platform and advantage?
What are the different types of ways where you can iterate over a list? : java collections