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

waht are architecture of web application?

2 Answers  


VSS Objectives

1 Answers  


Difference between Spring framework and Struts framework?

12 Answers   IBM, L&T, VAM,


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

0 Answers  


what is the IDE that you have used to write your java programs?

2 Answers   Inforica, Interface Software,






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

0 Answers  


what are advantages of HQL? what are advantages of Native SQL? what are advantages of Criteria API?

1 Answers   TCS,


what is difference between struts1.2 and struts2.0

1 Answers  


what is the difference between checked and unchecked Exceptions?

4 Answers   CTS,


Is it possible to create Userdefined Unchecked Exception also?If Yes, give an example?

1 Answers   HCL,


What is Generic in java? Where can we write Generic ( class or method or objects or etc...)? with simple example? Thanks, Bose. Infosys 2 In which way does a Primitive data type is passed ? Sun- Microsystems 4 what is the use of declaring constructor as private? Sai- Softech 5 what is difference between global methods and local methods? 1 What is meant by class loader and how many types are there? Apple 1 what is meaning of JIT? 4 What is an abstract class? Wipro 5 what is filters and its use? Virtusa 2 why is multiple inheritance not allowed in java? Elementus-Technologies 7 Differences between jdk 1.4 and 1.5 Wipro 4 is JVM platform dependent or independent..? IBM 6 what is main purpose of abstract class? 5 what is difference between colection and collections? Tech-Mahindra 11 What error occurs if a try-catch-finally statement sequence does not have a catch clause? 2 Explain the difference between scrollbar and scrollpane? 1 Explain the differences between public, private, protected and static? 4 Explain the difference between getAppletInfo and getParameterInfo? 1 Is Cegonsoft Pvt.Ltd. a good Institute? 4 Why only one Class is public in one file? Explain in details. Thanks in Advance. 11 Which method will get invoked first in a stand alone application?

0 Answers  


What is the use of log4j and how to make use of that in a application?

2 Answers  


Categories