Constructor
Constructor is a special non static member because :
1. Constructor name must be as same as classname.
2. Constructor is similar to method but it doesn't have any return type.
Why do we need constructor ?
To store all non static members in object.
Program:
- class P1
- {
- int a=10;
- P1( )
- {
- }
- void dell( )
- {
- }
- public static void main(String [ ] args)
- {
- P1 ref = new P1( );
- }
- }
Difference between Method and Constructor
Types of constructor
- No-argument constructor
- The constructor which does't having any formal argument.
- Parameterized constructor
- The constructor which has formal argument.
NOTE-
1) If the class is not having any constructor by default compiler will add no argument constructor during compile time is known as default constructor.
2) Every constructor will have three things
- PLI=(Pre Loading Instructions==To load/ store nonstatic members into obect
- IIB=(Instance Initializer Block=non-static Block)
- UWS=(User Written Statement)
1 Comments
Nice bhava
ReplyDelete