Boxed(True/False)

header ads

What is Constructor? Discuss Different Types of Constructor in Java?

* What is constructor? Discuss different constructor in java?

Ans:- A constructor in Java is a block of code similar to a method that's called when an instance of an object is created. A constructor resembles an interface method in java but it's not a method as it does not have a return type.




There are 4 different types of the constructor are here-

  • Default Constructor
  • No-argument Constructor
  • Private Constructor
  • Perameterized Constructor


Default Constructor:

If you do not implement any constructor in your class, java compiler inserts a default constructor in your class. This constructor is known as default constructor.

class A
{

}
class B extends A
{

}
class Test
{
A obj = new B(); // Dynamic binding
}

import java.io.*;
class Test
{
public static void main(String args[])  // args use for command line argument
{
BufferedReader br = new BufferReader(new InputStreamReader());
br.readLine();
}
}



Post a Comment

0 Comments