Java - Online Test - Default constructor -


Search Java Test Questions

 223 test questions in repository.

Java - Test Questions on 'Default constructor' - 5 questions found

What will be the output of following code ?

public class BuggyBread {
   private int x;
   private int y;
   BuggyBread(int x,int y){};
   public static void main(String[] args){
      BuggyBread buggybread = new BuggyBread();
Core Java
compilation error due to uninitialized element
compilation error due to constructor

  default constructor

What is a default constructor ?Core Java
Constructor without parameters declared by user
Constructor provided by Java if no constructor is declared
Constructor with empty body
All of the above


How can we create objects if we make the constructor private ?Core Java
We can't create objects if constructor is private
We can only create objects if we follow singleton pattern
We can only create one object
We can create new object through static method or static block

  constructor   private constructor

What is the problem with following code ?

public class Car extends Vehicle{
   int x;

   void Car(int y){
      x = 5;

   void Car(){
Core Java
We cannot use this() within normal method
We cannot chain methods
We cannot overload constructors
We cannot use return type void with overloaded methods


Default Constructor is provided by Java ... Core Java
To Reserve Memory
To provide at least one instance method
To Make it look good
To initialize the object state


comments powered by Disqus