Java Constructors | No Argument Constructor | Parameterized constructor

preview_player
Показать описание


******************** → A constructor initializes an object when it is created.
→ It has the same name as its class.
→ Constructors have no explicit return type.
→ Java automatically provides a default constructor if there is no explicit constructor.

Types of Java Constructors:
→ No Argument Constructor:
→ It doesn't accept any parameter.
Syntax:
Public class TestClass {
Int num
TestClass() {
num = 10
}
}

Parameterized Constructor:
→ It accepts parameters.
class TestClass {
int x

TestClass(int i) {
x = i
}
}

#Constructor #Java #ProgrammingLine #rake

*******************************************************

IMPORTANT PLAYLISTS:

Important Links:

*******************************************************

Subscribe my YouTube channels:

*******************************************************
Рекомендации по теме