7.5 Constructor Example in Java

preview_player
Показать описание
Constructor in java is a special type of method that is used to initialize the object.

Java constructor is invoked at the time of object creation. It constructs the values i.e. provides data for the object that is why it is known as constructor.

name of constructor in Java must be exactly same with the class on which you declare constructor,

A class in Java can have as many constructor as it and that is called constructor overloading in Java but signature of two constructor must not be same.

constructor in Java doesn't have return type

Every Class in Java has constructor, if no explicit constructor is specified by Programmer, Java Compiler inserts a no argument constructor inside class.
This is also called default Constructor in Java

You can use any access modifier with Java constructor. they can be public, protected or private. Default or no argument
constructor has same access modifier as class. You can also prevent a class from extension by making there constructor private.

Constructor in Java can not be abstract, static, final or synchronized

Constructor of parent class is executed before constructor of child class

there is no destructor in Java
Check out our courses:

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO20 (20% Discount)

For More Queries about Course, WhatsApp or Call: +919008963671

Subscribe to the channel and learn Programming in easy way.

Рекомендации по теме
Комментарии
Автор

You are an amazing teacher and very informative.

jameswhyte
Автор

thank you so much for these videos, they are really helping me to understand a lot of details that I did not care for before

diono
Автор

i am watching this in 2021 ...Still it is best

aniketsomkuwar
Автор

tnx sir. do you have another classes or videos to teach software Engineering II ?

yunesahmadi
Автор

Sir is there any of your video series on Data structures using C
if not can you recommend a series

sanketsule
Автор

@1:08 JVM is not responsible for providing constructor, compiler

pratikbhardwaj
Автор

sir, can u upload any videos for APTITUDE.because it is the starting round in all IT interview.☺️🙄

sherothkar
Автор

i found this video of yours little confusing.i liked your previous videos though

ABHIsaysHey
Автор

what should be the size of the object for the class Abc?

raghavareddy
Автор

I think, creating another class in same class file is not a good practice

I-believe-in-humanity
Автор

we cannot call constructor does it mean ?

mahdihassan
Автор

I thought constructors are inside class

vedd
Автор

public class Telusuko
{
public static void main(String[] args)
{
Abc obj = new Abc(); // constructor
}
}


class Abc // i am getting a error here saying "the type Abc is already defined
{
public Abc()
{
System.out.println("In Abc Constant");
}
}

karthikksk
visit shbcf.ru