File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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

which is valid statement in this question

majohnad majohnad

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

Rikko Verrijzer
Ranch Hand

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

Francois Roland
Ranch Hand

Joined: Jul 24, 2003
Posts: 34

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
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

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

Don't get me started about those stupid light bulbs.
subject: which is valid statement in this question
Similar Threads
ambiguous statements
Some Basic Questions
Some basic questions - part 2
exam qs- modifiers and identifiers-help
Abstract Method