Multiple Choice

  1. What do you lose when you add a constructor to a class?

  2. What is the most correct description of a constructor?

  3. How do we call the constructor depicted in the code snippet below?

     public class Point {
       private double x;
       private double y;
    
       // ...
    
       public Point(Point original) {
         this(original.x, original.y);
       }
     }
  4. Which code block contains a default constructor?

     // Code block A
     class Foo {
       public Bar() {
         // ...
       }
     }
     // Code block B
     class Bar {
       public Bar(int x) {
         // ...
       }
     }
     // Code block C
     class Bar {
       public Foo(int x) {
         // ...
       }
     }
     // Code block D
     class Bar {
       public Bar() {
         // ...
       }
     }

Last updated