Constructors and Constructor Overloading in Java (in brief)
Lecture By: Veeresh Basavaraj Hatti
Click the link below to download Notes of OOC-18CS45
https://sites.google.com/view/musicpluseducation/ooc-18cs45
A constructor in Java is a special method that is used to initialize objects. The constructor is called when an object of a class is created.
Constructor Parameters:
Constructors can also take parameters, which is used to initialize attributes.
Rules for creating Java constructor:
There are three rules defined for the constructor.
1. Constructor name must be the same as its class name
2. A Constructor must have no explicit return type
3. A Java constructor cannot be abstract, static, final, and synchronized
Types of Java constructors:
There are two types of constructors in Java:
Default constructor (no-arg constructor)
1.Parameterized constructor
2. Constructors and Constructor Overloading in Java
Java Default Constructor:
A constructor is called "Default Constructor" when it doesn't have any parameter.
Parameterized constructor:
A constructor which has a specific number of parameters is called a parameterized constructor.
Note: It is called constructor because it constructs the values at the time of object creation. It is not necessary to write a constructor for a class. It is because java compiler creates a default constructor if your class doesn't have any.
Видео Constructors and Constructor Overloading in Java (in brief) автора Программистский Лагерь
Видео Constructors and Constructor Overloading in Java (in brief) автора Программистский Лагерь
Информация
5 декабря 2023 г. 8:05:33
00:11:27
Похожие видео