• 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: 65218
95
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.
 
Kelvin Chenhao Lim
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Satish,

See if this article helps clarify your doubts: Composition vs. Inheritance
 
satish kumar chandran
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Kelvin.

It helped me to get it clear.

I've another query reg this.I want to know like,how JVM handles extends and reference variable in memory allocation.

Thanks in Advance...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic