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());
}
}

Answers were Sorted based on User's Feedback



How to call the m1() method of Base class in below snippet ? class Base { public void m1() ..

Answer / saurabh

In main():

::::::::::
Base ob = new Base();
ob.m1();
::::::::::

Is This Answer Correct ?    6 Yes 2 No

How to call the m1() method of Base class in below snippet ? class Base { public void m1() ..

Answer / suma.k

in main method

Base b1=new Base ();
b1.m1();

Is This Answer Correct ?    3 Yes 0 No

How to call the m1() method of Base class in below snippet ? class Base { public void m1() ..

Answer / mitu

class Derived extends Base
{
public void m1()
{
System.out.println("Derived m1");
}
public void m3()
{
System.out.println("Derived m3");
}
public void m26()
{
super.m1();
}

public static void main(String[] args)
{
Derived ob=new Derived();
ob.m1();
ob.m26();
}
}

Is This Answer Correct ?    1 Yes 0 No

How to call the m1() method of Base class in below snippet ? class Base { public void m1() ..

Answer / harshad

u can call super.m1();

Is This Answer Correct ?    1 Yes 0 No

How to call the m1() method of Base class in below snippet ? class Base { public void m1() ..

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

How to call the m1() method of Base class in below snippet ? class Base { public void m1() ..

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

More Java J2EE AllOther Interview Questions

who should use JNDI?

1 Answers  


What is an algorithm in java collection framework? : java collections

0 Answers  


Can any one tell me How to explain bank project desription in interview

3 Answers   Infosys, Wipro,


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

0 Answers   CTS,


what is difference between business deligate and session facade ?

2 Answers   Fidelity,






How do I find jre path in windows?

0 Answers  


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

0 Answers  


What are the classes in the java collection framework? : java collections

0 Answers  


what is the difference between through and throws?

2 Answers   HCL,


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

0 Answers   NSN,


HOW MUCH PERCENTAGE WE DEDUCT FOR OUR SUPPLIERS OR OTHER PROFESSIONALS

0 Answers  


where is JNDI being used in java platform?

2 Answers  


Categories