#javaforbeginners #java #javatutorial #ConstructorTypes #javaprogramming #javabasics #onlineclassCS #ConstructorInJava
Types of Constructor:
The Default Constructor has no argument to pass. It initialize the class variable with default value.
Class add
{
int a, b;
add()
{
a=7,b=10;
}
}
Class sample{
public static void main(String args[])
{
add obj = new add(); // obj.a=7 & obj.b=10
}
}
Type 2: Parameter Constructor:
Constructor has parameter to initialize the class variable.
Class add
{
int a, b;
add(int x, int y)
{
a=x;
b=y;
}
}
Class sample{
public static void main(String args[])
{
add obj = new add(9,11); // obj.a=9 & obj.b=11
}
}
Copy Constructor:
Constructor passed with class object,
Class add
{
int a, b;
add()
{
a=7,b=10;
}
add( add cpy)
{
a=cpy.a;
B=cpy.b;
}
}
Class sample{
public static void main(String args[])
{
add obj1 = new add(); // obj1.a=7 & obj1.b=10
add obj2 = new add(obj1); // obj2.a=7 & obj2.b=10
} }
#Constructor
Constructor in Java : • Learn Java Constructor | EasyTechCode
#JavaClassObject : • Learn How to Create Object in Java | Easy...
On this page of the site you can watch the video online Learn Java Constructor Types | EasyTechCode with a duration of hours minute second in good quality, which was uploaded by the user BetaCode 18 May 2022, share the link with friends and acquaintances, this video has already been watched 19 times on youtube and it was liked by 1 viewers. Enjoy your viewing!