wood burning stoves 2.0*
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 Java 8 in Action this week in the Java 8 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: 60082
    
  65

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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Extending vs Reference
 
Similar Threads
protected access
Extending vs Reference
Question on Anonymous Inner class
add property of type enum to class
Copy file