#43 Constructor in Java

preview_player
Показать описание
Check out our courses:

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO20 (20% Discount)

Udemy Courses:

For More Queries WhatsApp or Call on : +919008963671

In this lecture we will see:
- What are constructors in Java/
- Properties and use of a constructor
- Syntax of a constructor

#1
- When you create an object then in the heap memory, it will just create a blank object.
- If you do not assign values than the default values will be assigned like:
0 for int,
NULL for string
- We can also define values at the time of the creation of an object by giving our default values.

#2
Properties of a constructor:
- Constructor is almost similar to a method it has a name and it also has round brackets.
- The change in the constructor with respect to the method is that in the constructor we do not specify the return type.
- The name of a constructor must be the same as the class name.
- There is no need to call a constructor. It gets called automatically at the time of the creation of an object.
- At the time of calling the constructor, memory for the object is allocated in the memory.
- Constructors are called only once at the time of object creation. While method(s) can be called any number of times.

#3
Syntax of a constructor:
class human {
public Human()
{
statements;
}
}

More Learning :

Donation:
PayPal Id : navinreddy20
Рекомендации по теме
Комментарии
Автор

create a individual program for individual conepts don't be continue with the same program, why mean it collapsing for beginners..

parthasarathikrishnamoorth
Автор

constructors can not only be public, they can be public, private, protected and default too .
private constructors are used in singleton design pattern and in utility classes (like Math) also

Harshithkatukam
Автор

not for the begineers...I have seen all his concepts but bit difficukt for begineers to understand

raghasudha
Автор

Q1: Why constructor name and class name are same?
Q2: Why constructors doesn't have a return type?

rithikvarshan
Автор

It was helpful while I was struggling to understand it from my book.

shubhanjaliverma-sn
Автор

If you want to learn constructor please refer the vedio of durga sir they itself not understand the core Java concept.

_Radha_Krishna_
Автор

Why the age:12
Name: john
Not called 2 times when we have 2 objects?

Breakingbadtwd
Автор

Sir, New keyword just creates a obj with default values right? then what is the role of default constructor ?

sridharmurari
Автор

Sir if second object is created then another constructor will called?

JDMon
Автор

What about private constructors? How can I call it from my main class?

Gamuss
Автор

Why are you not updating VS Code? Please update VS Code.

puruagni
Автор

Sir video for school students pl class9, 10

bhagyashrik-hg
Автор

We can use methods for parameters then why to use constructor when we can do by method only, please need reply

roopagaur
Автор

Am I having dyslexia or the comments are not properly organised

ForeverChip
Автор

Sout shortcut is not working in my ide

shivamKumar-skjz
Автор

worst explaination i have seen on constructors

divyanshrautela-qneb