Help coderanch get a
new server
by contributing to the fundraiser
  • 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

Question from Marcus Green mock exam

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1880
Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic