Java Questions 31 - 40  «Prev  Next»

Java Questions 36

  1. Can constructors be overloaded?
    Answer:
    Yes, this is known as static polymorphsim.
  2. What does every constructor invoke in its superclass?
    Answer:
    Every constructor invokes the constructor of its superclass with an implicit call to super(), unless the constructor invokes an overloaded constructor of the same class.
  3. What is autoboxing?
    Answer:
    Autoboxing is when the Java compiler brings about an automatic transformation of a primitive type
    (int, float, double, char) to the corresponding wrapper type (Integer, Float, Double, Character) so that the programmer does not have to make the conversion using code.
  4. What type of access modifiers can constructors use?
    Answer:
    Constructors can use any access modifier including private.
  5. What must you observe when using a private constructor?
    Answer:
    A private constructor means only code within the class itself can invoke the private constructor.
  6. What happpens if a programmer creates his own constructor?
    Answer:
    If a programmer writes or creates his own constructor, the compiler will not provide a "no-args" constructor.

  7. Do abstract classes have constructors?
    Answer:
    Yes, abstract classes have constructors, and these constructors are always called when a concrete subclass is instantiated.
  8. What happens if a superclass contains a constructor other than the "no-args" constructor?
    Answer:
    If a superclass contains a constructor other than the "no-args" constructor, then the subclass must also contain the same constructor (without the "this" initialization) and a call to super();
  9. What kind of variables can a class consist of?
    Answer:
    A class can consist of a) instance fields and b) static fields.
    Local variables are valid for methods and blocks.
  10. What is an instance variable?
    Answer:
    An instance variable is defined within a class and outside any method.
    These variables receive default values after the class is compiled.