• 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

Question on Extensibility

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
ParentClass ObjectName = new ChildClass();
What does this exactly mean? What's its significance? Where it can be used?
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can make a parent reference point to a child object. What this means is that you only have access to methods and variables declared in the parent, but, if any of these non static methods are overridden then the method is called from the child class.

class parent
{
void method(){}
}
class child extends parent
{
void method(){}
}
now if you make a parent reference point to a child then the method in child is called. This is an example of polymorphism.
 
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Prashil Wasnik ,this is an example of "is an" relation, which means object of subclass is also an object of super class. This concept is the root for polymorphic behaviour of super class, which used for overriding of nonstatic methods.

class ParentClass
{
int method1()//1
{
// implementation
}
}

class ChildClass extends ParentClass
{

int method1()//2
{

}
public static void main(String arg[])
{
ParentClass a=new ParentClass();
a.method1();//calls 1
ParentClass a=new ChildClass();
a.method1();//calls 2
}
}

Hope it is clear.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic