Hi, 3.13) Which of these statements are true? Select all valid answers: (a) Transient variables will not be saved during serialization. (b) Constructors can be declared abstract. (c) The initial state of an array object constructed with the statement int a = new int will depend on whether the variable a is a local variable, or a member variable of a class. (d) Any subclass of a class with an abstract method must implement a method body for that method. (e) Only static methods can access static members. which are all true in the above question?
Hi, A) Transient variables will indeed not be saved when a object is serialized B) an abstract constructor... Creating an abstract class, not a verry good idea. C) the initial state of an array is the same whether it is global or local D) Its legal to extend a class in a other abstract class, so not every subclass needs to implements an abstract method. E) Every method can access a static member of that class. That leaves only A to be true. Hope this helps?
Hi, I agree with Rikko's answers. I'll just refine the justification of answer B: An abstract class can indeed have a constructor. But, that constructor cannot be abstract. Constructors are never inherited from superclasses (abstract or not). But you can always refer to a superclass constructor like this:
[ July 25, 2003: Message edited by: Francois Roland ]
Constructors are never inherited from superclasses (abstract or not). But you can always refer to a superclass constructor like this: explicit call to super in subclass's constructor
You don't have to make this explicit call. If there is no call to either this or super in subclass's constructor, then the compiler puts in a call to the no-argument constructor in the parent. Thus, in this case, the explicit call is superfluous (even though it doesn't harm...) So the code below runs well:
Output: Z The case you need to make an explicit call: if you try to extend an class [B]tht does not have a no-argument constructor, then you must explicitly call super() with one of the argument forms that are supported by constructors in the parent class: so this will not compile (no no-arg constructor in Z):
whereas this will compile and run:
SCJP 1.4, SCWCD, SCBCD, IBM XML, IBM Websphere 285, IBM Websphere 287