Java Constructor Overloading Interview MCQ Questions and Answers

Study and learn Interview MCQ Questions and Answers on Java Constructor Overloading. Attend job interviews easily with these Multiple Choice Questions. You can print these Questions in default mode to conduct exams directly. You can download these MCQs in PDF format by Choosing Print Option first and Save as PDF option next using any Web Browser.

Go through Java Theory Notes on Constructor Overloading before reading these objective questions.



1) A Java constructor is like a method without ___.
A) statements
B) return type
C) argument list
D) None
Answer [=]
Answer[=]
2) The name of a constructor and the name of a class are ___.
A) Same
B) Different
C) -
D) -
Answer [=]
Answer[=]
3) The placement of a constructor inside a class should be ___.
A) Always at the beginning of class
B) Always at the end of class
C) Anywhere in the class
D) None
Answer [=]
Answer[=]
4) The purpose of a Java constructor is ___.
A) Initialization of variables with passed data
B) Writing custom code
C) Accepting other objects as inputs
D) All the above
Answer [=]
Answer[=]
5) Memory is allocated to an object once the execution of ___ is over in Java language.
A) main method
B) constructor
C) destructor
D) None
Answer [=]
Answer[=]
6) What is the output of the below Java program?
public class TestingConstructor
{
  void TestingConstructor()
  {
    System.out.println("Amsterdam");	
  }

  TestingConstructor()
  {
    System.out.println("Antarctica");	
  }
	
  public static void main(String[] args)
  {
    TestingConstructor tc = new TestingConstructor();
  }
}
A) Antarctica
B) Amsterdam
C) No output
D) Compiler error
Answer [=]
Answer[=]
7) In Java, a constructor with no parameters or no arguments is called ___ constructor.
A) Default constructor
B) User-defined constructor
C) -
D) -
Answer [=]
Answer[=]


 

8) In Java, a constructor with one or more arguments or parameters is called a ___ constructor.
A) Default constructor
B) User-defined constructor or Non-default constructor
C) -
D) -
Answer [=]
Answer[=]
9) The compiler adds a default no-argument constructor to a class if it ___.
A) does not define a constructor at all.
B) defines at least one constructor with arguments
C) -
D) -
Answer [=]
Answer[=]
10) Overloading of constructors in Java means adding more than ___ constructors with the different argument list.
A) 1
B) 2
C) 3
D) 8
Answer [=]
Answer[=]
11) What is the output of the below Java program with constructors?
public class Constructor2
{
  int count=10;
  Constructor2(int count)
  {
    System.out.println("Count=" + count);
  }

  public static void main(String[] args)
  {
    Constructor2 con = new Constructor2();
  }
}
A) Count=0
B) Count=10
C) Compiler error
D) None of the above
Answer [=]
Answer[=]
12) A constructor can call another overloaded constructor using the ___ keyword in Java.
A) super
B) local
C) con
D) this
Answer [=]
Answer[=]
13) What is the output of the below Java program with overloaded constructors?
public class Constructor3
{
  int birds=10;
  Constructor3()
  {
    this(20);
  }
  Constructor3(int birds)
  {
    System.out.println("Birds=" + birds);
  }

  public static void main(String[] args)
  {
    Constructor3 con = new Constructor3();
  }
}
A) Birds=0
B) Birds=10
C) Birds=20
D) Compiler error
Answer [=]
Answer[=]
14) In Java, you can pass __ variables from one constructor to another overloaded constructor.
A) local variables
B) static variables
C) non-static variables
D) local and static variables
Answer [=]
Answer[=]


 

15) Choose the correct way of calling the second constructor from the first constructor in the below code options.
A)
Constructor5()
{
  int a=30;
  this('A');
}
Constructor5(char c)
{
 //
}
B)
Constructor5()
{
  int a=30;
  this('A');
  System.out.println("Success");
}
Constructor5(char c)
{
  //
}
C)
Constructor5()
{
  this('A');
  System.out.println("Success");
}
Constructor5(char c)
{
  //
}
D) All the above
Answer [=]
Answer[=]
16) What is the output of the below Java program with many constructors?
public class Constructor7
{
  Constructor7(int a)
  {
    System.out.println("Book=" + a);
  }
  Constructor7(float a)
  {
    System.out.println("Pen="+ a );
  }
  public static void main(String[] args)
  {
    Constructor7 con = new Constructor7(50.5f);
  }
}
A) Book=50
B) Pen=50.5
C) Compiler error
D) None of the above
Answer [=]
Answer[=]
17) What is the output of the below Java program with many constructors?
public class Constructor8
{
  Constructor8(boolean a)
  {
    System.out.println("MODEM="+ a );
  }
  Constructor8(float a)
  {
    System.out.println("ROUTER=" + a);
  }
  public static void main(String[] args)
  {
    Constructor8 con1 = new Constructor8(50);
    Constructor8 con2 = new Constructor8(false);
  }
}
A)
ROUTER=50.0
MODEM=false
B)
ROUTER=50
MODEM=false
C) Compiler error
D) None
Answer [=]
Answer[=]
18) What is the output of the below Java program with overloaded constructors?
public class Jiraffe
{
  Jiraffe(int sugarcanes)
  {
    System.out.println("Eats "+ sugarcanes + " Sugarcanes");
  }
  Jiraffe(int age, int...sugarcanes)
  {
    System.out.println("Eats "+ sugarcanes[0] + " Sugarcanes");
  }
  public static void main(String[] args)
  {
    Jiraffe jiff2 = new Jiraffe(40);
    Jiraffe jiff = new Jiraffe(5,10);
  }
}
A)
2.Eats 40 Sugarcanes
2.Eats 10 Sugarcanes
B)
1.Eats 40 Sugarcanes
2.Eats 10 Sugarcanes
C) Compiler error
D) None
Answer [=]
Answer[=]
19) Choosing a suitable overloaded constructor happens at ___ time in Java.
A) Compile-time
B) Run time
C) -
D) -
Answer [=]
Answer[=]
20) Java constructor overloading follows ___ principle in Object-Oriented programming.
A) Inheritance
B) Encapsulation
C) Polymorphism
D) None
Answer [=]
Answer[=]
21) Java allows calling or invoking a method from a constructor. State TRUE or FALSE.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
Answer[=]


 

22) What is the output of the below Java program?
public class Constructor9
{
  Constructor9()
  {
    show();	
  }
  void show()
  {
    System.out.println("JAM JAM");
  }
  public static void main(String[] args)
  {
    Constructor9 con = new Constructor9();
  }
}
A) JAM JAM
B) No output
C) Compiler error
D) None
Answer [=]
Answer[=]


Like or Share

Show some care. Like or Subscribe. [FB]...[Youtube]

C MCQ App by ExamTray 

Android APP

Java MCQ App by ExamTray 

Android APP
ALL MCQ App by ExamTray Android APP

Ad

 

Try Some Java Books

Book Price
1. Java - The Complete Reference  Check Price
2. Core Java: An Integrated Approach, Black Book Check Price
3. Java All-in-One for Dummies Check Price
4. OCP Java SE 8: Programmer II Check Price
5. Programming with Java Check Price
6. Head First Java Check Price

We may get some affiliate commission for the above purchases.