• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

which is valid statement in this question

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 34
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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:
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to clarify, putting an abstract modifier on a constructor will result in a compiler error.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic