Game Preview

Constructors

  •  English    15     Public
    Create constructors of a class by initializing its instance local variables within a program code to set the initial state of the created object
  •   Study   Slideshow
  • You have created a Motorcycle class which has a constructor with no parameters. Which of the following statements will construct an object of this class?
    Motorcycle myBike = new Motorcycle();
  •  10
  • When an object is created from a class, the object is called a/an ________ of the class.
    instance
  •  10
  • True or False: Private instance variables are the interface to the class.
    False
  •  10
  • True or False: All instance variables should be declared as private and most instance methods should be declared as public
    True
  •  10
  • True or False: A constructor must have the same name as the class name.
    True
  •  10
  • True or False: A call to a constructor must always have construction parameters.
    False
  •  10
  • True or False: A constructor initializes the instance variables of an object.
    True
  •  10
  • True or False: A class can have more than one constructor.
    True
  •  10
  • Which statement calls a constructor with no construction parameters?
    Circle c = new Circle();
  •  10
  • A constructor is invoked when _________________ to create an object.
    the new keyword is used
  •  10
  • True or False: A constructor should always return a value.
    False
  •  10
  • True or False: A class can have only one constructor.
    False
  •  10
  • If you do not provide a constructor in a class, which of the following is correct?
    The compiler will generate a constructor with no arguments.
  •  10
  • What is wrong with this code?
    The constructor must not have a return type declared.
  •  10
  • You are creating a class named Employee. What is the statement that correctly declares a constructor for this class?
    public Employee()
  •  10