Saturday 4 May 2013

What Is Constructor in Java?

 A constructor is a special member method which will call by the JVM automatically whenever an object is created by placing over own values without placing the default value.

Advantages of constructors:


If we use the constructor concept add a part of over the java program, we get the following advantage.

1. It eliminates in placing default values.

2. It eliminates in calling ordinary method. The purpose of constructor concept is that it initialized  the object.

.

Properties/characteristic of constructor:


 In over the java program, if we want to make use of constructor, the java programmer must follow the rules.

1. Constructor will be called automatically are implicitly whenever an object is created.

2. Constructor name must be similar to class name.

3. Constructor will not return any value even void also (if we write any return type in java, which is by default treated as an ordinary method).

4. The modified of the constructor should not be static because constructor will be called each time as a when an object is created...

5. Constructor will not be inherited because each constructor of class must initialize its own data member.

6. A constructor of a class may are may not be private.

7. If the constructor is private than the object of corresponding class can’t be created within the context of some other class, but it can be possible to create it object only within the context scope of class.

8. If a constructor is not private than the corresponding class object can be created everywhere i.e. no restriction on the accessibility of the constructor.

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More