• Post Reply Bookmark Topic Watch Topic
  • New Topic

final,abstract and strictfp  RSS feed

 
raavi kumaar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,

Which of the following declarations are correct w.r.t. final, abstract and strictfp ?

(a) public final class xyz {}
(b) public abstract class xyz {}
(c) strictfp final class xyz {}
(d) final abstract class xyz {}


Bye,
Ravi Kumar
[ October 29, 2007: Message edited by: raavi kumaar ]

[ October 29, 2007: Message edited by: Ilja Preuss ]

Answer to the above question-

Option (a) - Correct, It is a final class declaration

Option (b) - Correct, It is an abstract class declaration.

Option (c) - Correct, strictfp can be applied to classes and methods, but not variables. Try this example -

public strictfp class Airplane {

//uncomment the below line and try compiling the code
//strictfp int x=10;
public strictfp void takeoff (){}

public strictfp void fly () {}

public strictfp void land(){}
}


Option (d) - Incorrect, Going by definition, final classes cannot be extended while abstract classes must be implemented ( by concrete classes ). Given this information , it is illegal (and of course invalid) to have final and abstract in the same declaration.

[ October 30, 2007: Message edited by: raavi kumaar ]
[ October 30, 2007: Message edited by: raavi kumaar ]
 
abhishek pendkay
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a and b are correct

d is wrong because a class cannot be both final and abstract it can be either final or abstract
[ October 29, 2007: Message edited by: abhishek pendkay ]
 
satyabrat mishra
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
only (d) final abstract class xyz {} is wrong.
a,b and c are right.
 
sudhir nim
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
d. is invalid
A class can not be both final and abstract.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi,

I deleted your email address, because we want to foster discussion on these forums, so that everyone can benefit from it. If you want to be notified when someone replies to this thread, please use the watch feature of this forum.

Also take a look at http://faq.javaranch.com/java/UseTheForumNotEmail and http://faq.javaranch.com/java/DoYourOwnHomework. I'm positive that taking those tips into account will improve your experience here on the Ranch.

Have fun, Ilja
 
raavi kumaar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by satyabrat mishra:
only (d) final abstract class xyz {} is wrong.
a,b and c are right.


You are right Satyabrat!!!

Ravi
http://www.devsquare.com/adc/dsweb/
[ October 29, 2007: Message edited by: raavi kumaar ]
 
raavi kumaar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sudhir nim:
d. is invalid
A class can not be both final and abstract.


Kudos, you are right Sudhir.

Ravi
http://www.devsquare.com/adc/dsweb/
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!