Contact Us || Privacy Policy || About Us |
|
Constructor in Java→ Constructor is a special type of method also contains collection of statements that is used to initialize objects. When an object of a class is created. It can be used to set initial values for object attributes:. Rules for creating constructor
Types of Java constructors→ There are two types of constructors in Java:
1) Default Constructor in javaIf you don't define a constructor in a class, then compiler automatic creates a Default Constructor for the class, it is also known as no arguments. Example1 : Output ![]() Example2 : Output ![]() 2) Parameterized Constructor in java→ Constructor that have parameters is known as parameterized constructor. Example1 : Output ![]() Constructor Overloading in JavaConstructor overloading is a technique, more than one constructor with different parameter list, and each constructor performs a different task . Example1 : Output ![]()
Next TopicStatic Keyword in Java
|