File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extending vs Reference

 
satish kumar chandran
Greenhorn
Posts: 6
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic