Test Series - java

Test Number 51/64

Q: A Java constructor is like a method without ___.
A. statements
B. return type
C. argument list
D. None
Solution: no solution
Q: The name of a constructor and the name of a class are ___.
A. Same
B. Different
C. -
D. -
Solution: no solution
Q: 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
Solution: no solution
Q: 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
Solution: no solution
Q: Memory is allocated to an object once the execution of ___ is over in Java language.
A. main method
B. constructor
C. destructor
D. None
Solution: no solution
Q: 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
Solution: Here the constructor is TestingConstructor() without return type.
Q: In Java, a constructor with no parameters or no arguments is called ___ constructor.
A. Default constructor
B. User-defined constructor
C. -
D. -
Solution: no solution
Q: 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. -
Solution: no solution
Q: 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. -
Solution: no solution
Q: Overloading of constructors in Java means adding more than ___ constructors with the different argument list.
A. 1
B. 2
C. 3
D. 8
Solution: no solution

You Have Score    /10