Two Laptop Bag*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes which is valid statement in this question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "which is valid statement in this question" Watch "which is valid statement in this question" New topic
Author

which is valid statement in this question

majohnad majohnad
Greenhorn

Joined: Jan 01, 2003
Posts: 24
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[10] 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?


zxjohn
Rikko Verrijzer
Ranch Hand

Joined: Jul 22, 2003
Posts: 34
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?

Rikko
Francois Roland
Ranch Hand

Joined: Jul 24, 2003
Posts: 34

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 ]

--
Brown belt on KnowledgeBlackBelt.com.
cyril vidal
Ranch Hand

Joined: Jul 02, 2003
Posts: 247

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
Darren McLeod
Greenhorn

Joined: Jul 07, 2003
Posts: 19
Just to clarify, putting an abstract modifier on a constructor will result in a compiler error.


SCJP, SCBCD
 
 
subject: which is valid statement in this question