• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Extending vs Reference

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
reply
    Bookmark Topic Watch Topic
  • New Topic