filmov
tv
#4.3 Java Tutorial | Constructor Example
Показать описание
Whenever you see round brackets in Java, it simply means that it is a method.
Constructor:
A constructor is a block of codes similar to the method. It is called when an instance of the class is created.
- It is a special type of method that is used to initialize the object.
-Whenever you create an object by saying new calc that calc and bracket is a constructor.
- Constructor is very important when you create an object.
- To call the constructor, we follow the syntax:
Calc obj= new Calc();
- By default, java gives you one constructor for the class with no parameters as it gives for Calc.
- The constructor with Java allocates the memory, thus it is used for allocating the memory.
- Java calls a default constructor if there is no constructor available in the class.
- We can also define our own constructors.
- We can also have two constructors in the same class provided they have a different signature.
- While creating an object if you pass a value, it will call that particular constructor which takes a value of its data type and it will assign that value to the constructor.
- You have to match the parameters as the number of values you are passing.
The syntax for defining constructor:
public Calc()
{
}
Point to remember about constructor:
- Constructor has the same name as a class name.
- Constructor does not return anything, so we do not specify the return type in a constructor.
- We do not need to call the constructor, it will be called automatically when the object is created.
Types of Constructors:
- A constructor with parameters is known as a Parameterized constructor.
- A contructor with no parameters that are given by Java is known as a Default constructor.
In this video we will see :
- What is constructor
- Example of Constructor
- How to create constructor
- Default constructor
- Characteristics of Constructor
- Assigning value through constructor
- Parameterized Constructor
- Constructor overloading
More Learning :
Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
Constructor:
A constructor is a block of codes similar to the method. It is called when an instance of the class is created.
- It is a special type of method that is used to initialize the object.
-Whenever you create an object by saying new calc that calc and bracket is a constructor.
- Constructor is very important when you create an object.
- To call the constructor, we follow the syntax:
Calc obj= new Calc();
- By default, java gives you one constructor for the class with no parameters as it gives for Calc.
- The constructor with Java allocates the memory, thus it is used for allocating the memory.
- Java calls a default constructor if there is no constructor available in the class.
- We can also define our own constructors.
- We can also have two constructors in the same class provided they have a different signature.
- While creating an object if you pass a value, it will call that particular constructor which takes a value of its data type and it will assign that value to the constructor.
- You have to match the parameters as the number of values you are passing.
The syntax for defining constructor:
public Calc()
{
}
Point to remember about constructor:
- Constructor has the same name as a class name.
- Constructor does not return anything, so we do not specify the return type in a constructor.
- We do not need to call the constructor, it will be called automatically when the object is created.
Types of Constructors:
- A constructor with parameters is known as a Parameterized constructor.
- A contructor with no parameters that are given by Java is known as a Default constructor.
In this video we will see :
- What is constructor
- Example of Constructor
- How to create constructor
- Default constructor
- Characteristics of Constructor
- Assigning value through constructor
- Parameterized Constructor
- Constructor overloading
More Learning :
Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
Комментарии