ITProWire News Archives About Us Feedback


Click to Play

Bringing Search and CMOs...
There is a growing need to connect the search industry to CMOs. At this point, CMOs are not engaged with search and yet they control the money. Brian... Cutts...

Recent Articles

OpenOffice Considers The Addition Of Ribbon UI
Project Renaissance is an OpenOffice.org project aiming to deliver a new user interface (UI) for OOo. The team recently completed the prototyping phase and is asking for users to provide feedback on the 8 UI options.

Every Good IT Department Needs A Good Recovery Plan
After reading about Lisa Barone's laptop being stolen, I got into a bit of a discussion about how I use cloud computing for part of my backup and disaster...

Mobile Software Development Made Easier Through...
Android continues to build momentum by making life easier for developers and possibly converting a rival mobile OS Symbian backer Nokia to...

Directory Board Established To Srengthen Neutral...
The EOS directory, the list of enterprise open source applications launched two years ago by Optaros, has recently been handed over to Bruno von Rotz, initial sponsor of the initiative and well known open...


08.27.09

How To Build And Call Superclasses

By Vaibhav Pandey

Inheritance is the core concept of Object oriented programing and Java programming Language. Since every subclass has exclusive rights to use the every resource of its superclass. Constructor of superclass holds important position in this regard.

There are many functions a subclass can import by calling the constructor of its superclass. The call to the Superclass constructors can be made by using the ' super ' keyword. The main points to remembered in case of using super keyword are as follows:-

1. The default Constructor of the superclass is invoked even if the super() method is not called in the subclass. It is also invoked if you do not pass any arguments to super(). If the default constrictor is not available,compiler generates an error.

2. You can invoke a special constructor of the superclass by passing arguments to the super method,if the constructor is overloaded in the superclass.

3. The super() method must be the first statement in the constructor of the subclass.

Lets take a look at following example:- The example illustrates how you can call a super class constructor.

The Superclass

class Car
{
Strring Name;
int seats=4;

Car(){
. . . . .
}

Download Now

Car(int seats,String Name){
. . . .
}
}

Subclass which invokes the superclass constructor

public class Subaru extends Car{
int wheels;

public Subaru(){
super(4,"Subaru Impreza");
wheels=4;
}
}

Here the constructor of superclass is invoked by the method call super(4,"Subaru Impreza") and you can call the default constructor by placing your call super(). By following the way you can invoke the superclass constructor which can be helpful in many tasks in your application.

Comments


About the Author:
Vaibhav Pandey got offered employment from an Indian Multinational IT Company. He is 21 years old. He has a huge interest in Java programming and has liked it from his study days. Vaibhav loves to blog and share his experiences and thoughts. He now resides in Lucknow, a state capital in India. Check out his blog at http://javatutorialsworld.blogspot.com.
About ITProWire

News and updates for the IT professional





ITProWire is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
PerlProNews.com SQLProNews.com
SysAdminNews DevWebPro.com
LinuxProNews.com WirelessProNews.com
CProgrammingTrends.com ITCertificationNews.com





-- ITProWire is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2009 iEntry, Inc. All Rights Reserved Privacy Policy Legal

archives | advertising info | news headlines | free newsletters | comments/feedback | submit article


ITProWire Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact