• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extending vs Reference

 
satish kumar chandran
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the main difference between extending a class ,accessing its methods and creating a reference variable and accessing the class methods?
 
Kamlesh Kumar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Extending a class means inheriting some behavior of the base class. Suppose you have class Derived which is extending class Base
class Base
{
public void someMethod(){
}
}
class Derived extends class Base
{
public void anyMethod(){
super.someMethod();//This is the way you call a base class method
}
}

While if we want to call the method of clas Derived we can do this way...

Base obj=new Derived();
obj.anyMethod();

I think this example clears your concept...
 
satish kumar chandran
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by satish kumar chandran:
What is the main difference between extending a class ,accessing its methods and creating a reference variable and accessing the class methods?


Could you make it more clearer...
Also,how JVM handles it when Extending and Creating a Reference Variable.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. This forum is for questions on JSP.

This post has been moved to a more appropriate forum.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic