Java Questions 36
- Can constructors be overloaded?
Answer:
Yes, this is known as static polymorphsim.
- 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.
- 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.
-
What type of access modifiers can constructors use?
Answer:
Constructors can use any access modifier including private.
- 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.
- 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.
- Do abstract classes have constructors?
Answer:
Yes, abstract classes have constructors, and these constructors are always called when a concrete subclass is instantiated.
- 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();
- 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.
- 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.