J2EEOnline J2EE  





Java Questions 41 - 50  «Prev  Next»

Java Constructor Characteristics(Questions)

  1. Are Java constructors inherited?
    Answer:
    No. A subclass inherits all the members (fields, methods, and nested classes) from its superclass.
    Constructors are not members, so they are not inherited by subclasses, but the constructor of the superclass can be invoked from the subclass.
  2. Do constructors have return types?
    Answer:
    No. Only methods have return types.
  3. How many constructors will be invoked in an object's inheritance tree?
    Answer:
    All of the constructors in an object's inheritance tree will be invoked when the object is instantiated using new.
  4. How can a constructor invoke another constructor of the same class?
    Answer:
    A constructor can invoke another constructor of the same class using the this keyword .
  5. What must every constructor have in the first line of its body?
    Answer:
    Every constructor must have
    1. this or
    2. super
    as the first statement (although the compiler can insert this for you).
    Have both 1) this and 2) super in the first line of a constructor will cause a compiler error.
  6. What is characteristic of class variables?
    Answer:
    Static members are tied to a class and not to an instance.
  7. How do you access a static member?
    Answer:
    Use the class name with the dot operator.
  8. How is the IS-A relationship expressed?
    Answer:
    The IS-A relationship is expressed with the keyword extends.
  9. What is true about reference variables in Java?
    Answer:
    A reference variable is always of a single unchangeable type, but it can refer to a subtype object.
  10. Can constructors be overridden in Java?
    Answer:
    No.Constructors can be overloaded but not overridden because constructors are not inherited.
    Notes: 1. A reference variable can refer to a subtype object.