Constructor in Java: Author: Itvoyagers Website: Post
Constructor in Java: Author: Itvoyagers Website: Post
Author : ITVoyagers
Website : itvoyagers.in
Post :
https://itvoyagers.in/constr
uctor-in-java/
2 Content
ITVoyagers - itvoyagers.in
3 Why we need constructor?
Suppose we create a class Student with some attributes.
ITVoyagers - itvoyagers.in
4 Why we need constructor?
So now if we want to create object of this class and assign values to its
variables we have to use instance of object.
If we use instance of class object
to assign the value to variables
then it will increase the LOC.
We have assign values to each
variable separately and this is
not possible with the classes
having more variables.
This is where Constructor
comes in play.
ITVoyagers - itvoyagers.in
5 Use of constructor.
Simple Definition
Constructor is a method which name is same as class name and it get executed at
the time of object creation.
ITVoyagers - itvoyagers.in
6 Type of constructor.
ITVoyagers - itvoyagers.in
7 Parameterized Constructor
ITVoyagers - itvoyagers.in
8 Parameterized Constructor
ITVoyagers - itvoyagers.in
9 Non-Parameterized Constructor
ITVoyagers - itvoyagers.in
10 Non-Parameterized Constructor
ITVoyagers - itvoyagers.in
11 Rules for constructor.
Constructor doesn't have any return type.
Name of constructor is same as class’s name.
ITVoyagers - itvoyagers.in
12 Advantages of constructor.
ITVoyagers - itvoyagers.in
Follow us on
13
https://www.facebook.com/itvoyagers/
https://twitter.com/ITVoyagers
https://www.instagram.com/itvoyagers_official/
https://www.reddit.com/user/ITVoyagers ITVoyagers
OFFICIAL https://in.pinterest.com/itvoyagers/
https://www.linkedin.com/in/itvoyagers-vgitcs-673642172/
https://www.slideshare.net/vgitcsofficialedupoi
ITVoyagers - itvoyagers.in