Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question from Marcus Green mock exam

 
janne s
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the following represent valid code if it is the entire contents of a file called whitney.java?


1 abstract final class whitney{}
2 public final class whitney extends Object{}
3 public abstract class whitney{}
4 protected class whitney{}

The Correct Answer

2) public final class whitney extends Object{}
3) public abstract class whitney{}


I think answer 2 is wrong. If i'm worng pls explain.

Thank you in advance
jaya
[ November 08, 2004: Message edited by: jaya merugu ]
 
Toms Liepins
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi jaya, i believe that you have not understood the 'final' modifier. Final class/method can not be extended/overriden, however it DOES NOT mean that the final class ITSELF could not extend another nonfinal class. Answer 2 is correct (if you don't believe, try compiling
 
Krishna Srinivasan
Ranch Hand
Posts: 1874
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer 2,3 are correct.
why answer 2 is wrong. canu you tell the reason?
answer 2 syntax is perfectly valid.
 
Atul Chandran
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Every class extends Object class implicitly. But explicitly mentioning it does not result in an error. An analogy to instance variables will make it clear.

String a;//a will be assigned null by default.
String b=null;//is legal and null is assigned to b.
similarly
class A{} //A will extend Object by default
class B extends Object {} //legal and B extends Object class.
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It may seem a somewhat obscure point to test if you know that everything inherits from Object, even if it is not explicitly stated. However the great ancestor Object class provides some functionality that is used in threading, so it does have a practical application.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic