• 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

keyword Super

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone explain what exactly Super means?
thanks
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Divya,
super is a refernce to the immediate parent object of this. All objects have a super except for the granddaddy class Object. So if I have a class DaddyFoo (public class DaddyFoo) and a subclass BoyFoo (public class BoyFoo extends DaddyFoo) then Object is the super of DaddyFoo and DaddyFoo is the super of BoyFoo.
Hope this helps,
Michael Morris
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and if you want to reference a method in the parent class, preface it with super... eg
super.aMethod();
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
super refers to the objects immediate parent.
U can use the super keyword to explicitly call a base class method.
Calling super in the constrcutor calls the base class constructor.
Here is a small sample to clarify things:
class Base()
{
}
 
Rajeshwari Natarajan
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
super refers to the objects immediate parent.
U can use the super keyword to explicitly call a base class method.
Calling super in the constrcutor calls the base class constructor.
Here is a small sample to clarify things:
class Base
{
private String name;
Base(String name)
{
this.name = name;
}
}
class Derived
{
Derived(String name)
{
super(name);
System.out.println("Derived class constructor");
}
}
 
Rajeshwari Natarajan
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry abt the incomplete posts..here is the proper one..

super refers to the object's immediate parent.
U can use the super keyword to explicitly call a base class method.
Calling super in the constrcutor calls the base class constructor.
Here is a small sample to clarify things:
class Base
{
private String name;
Base(String name)
{
this.name = name;
}
}
class Derived extends Base
{
Derived(String name)
{
super(name);
System.out.println("Derived class constructor");
}
}
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic