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

which book is the best for preparing for SCWCD 1.5

4 Answers   Google,


whatis arguments &what is default argument

2 Answers   CTS,


Am chittibabu from vadavalli, My father name is nanjan.he is working in state bank of india at vadavalli, My mother name is ramal. She is house wife. My brother name is rajaram he is working in Privete Company. I was born on 25-january-1984 at bhavanisager in Erode District. I have completed my school in government higher secondary school bhavanisager. After that I came to coimbatore for higher study.i have joined Bsc computer science in sri ramalinga sowdambigai college of science and commerce, affiliated by bharathiyar university, coimbatore. In the same college, I have continued UG degree also. but I got a job in Systech infovation as a software programmer,so I discontinued Msc Degree.I have one and half years experience from this concern. Here I have completed two products; one is Tranport management solution for balaji goods carriers at tirupur. Another one is Embroidery Management Solution for Angel Embroidery at tirupur. After that I got an another job in metis technologies as senior software engineer. I have one year experience from this company.here I working in school management product.it is developing version by version.

3 Answers  


What is the servletcontext listener and what is JspContext and page context pls tell in simple words.

1 Answers   IBM,


What is Visual Source Safe(source control Tool)?

1 Answers  






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

6 Answers   Cap Gemini, TCS,


Explain the OOPS concept in Realtime Scenarion ? Take example as CAR. Please explain indetail ?

0 Answers   Cap Gemini,


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

0 Answers  


"Sun Certified Java Programmer" This is one String , we need to print SCJP, write the java code dynamically? pls reply this questions

6 Answers   Photon,


lll

1 Answers  


What are the interfaces in java collections? : java collections

0 Answers  


wnet use DAO design in u r project?

1 Answers   Godrej,


Categories