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
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 |
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 |
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 |
which book is the best for preparing for SCWCD 1.5
whatis arguments &what is default argument
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.
What is the servletcontext listener and what is JspContext and page context pls tell in simple words.
What is Visual Source Safe(source control Tool)?
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()); } }
Explain the OOPS concept in Realtime Scenarion ? Take example as CAR. Please explain indetail ?
What is an algorithm in java collection framework? : java collections
"Sun Certified Java Programmer" This is one String , we need to print SCJP, write the java code dynamically? pls reply this questions
lll
What are the interfaces in java collections? : java collections
wnet use DAO design in u r project?