Constructor In Java
Note -
The difference between constructor, and method -
Example 1-
package javaLearnings; |
Example 2 -
package javaLearnings; |
Example 3-
package javaLearnings; |
Example 4-
class Sample{ |
Types of constructor
There are three types of constructor in java given as follows-
Default Constructor
Example -
Output :
Parameterized Constructor
A constructor with parameter is called parameterised constructor you must pass the value at the time of object creation if your class have parameterised constructor.
package javaLearnings; } |
Output -