This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Extending vs Reference Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Extending vs Reference" Watch "Extending vs Reference" New topic
Author

Extending vs Reference

satish kumar chandran
Greenhorn

Joined: Nov 22, 2007
Posts: 6
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

Joined: Apr 17, 2006
Posts: 8
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

Joined: Nov 22, 2007
Posts: 6
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

Joined: Jan 10, 2002
Posts: 61103
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Kelvin Chenhao Lim
Ranch Hand

Joined: Oct 20, 2007
Posts: 513
Hi Satish,

See if this article helps clarify your doubts: Composition vs. Inheritance


SCJP 5.0
satish kumar chandran
Greenhorn

Joined: Nov 22, 2007
Posts: 6
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...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Extending vs Reference