| Author |
Question is ambigitive
|
Lanka Prasad
Greenhorn
Joined: Nov 14, 2004
Posts: 21
|
|
Anyone tell me whether the following statement is true or not. A final class may not have any abstract method. I think this is false since it means "A final class may have abstract method". But a practice tester I found it as true. I am very dissapointed about this meaning.
|
SCJP 1.4
|
 |
rajeshwar Rao
Ranch Hand
Joined: Mar 20, 2006
Posts: 31
|
|
A final class may not have any abstract method. This statement is not false because as we know if a super class contains an abstract method it need to be implemented by the derived class. But a final class cannot be inherited by any other derived class. Actually we declare a final class so that it is not inherited by any another class. I hope you are getting it. Yes it is of no use to declare abstract methods in final class but we can declare abstract methods in final class. Please correct me if i am wrong.
|
 |
Edisandro Bessa
Ranch Hand
Joined: Jan 19, 2006
Posts: 584
|
|
Hi rajeshwar, I think your last affirmation is not correct.
Yes it is of no use to declare abstract methods in final class but we can declare abstract methods in final class.
Once you declared a method as abstract, the compiler obligates you to declare the entire class as abstract. So a final class containing an abstract method would be forced to be declared as final abstract class MyClass which for sure is illegal.
|
"If someone asks you to do something you don't know how to, don't tell I don't know, tell I can learn instead." - Myself
|
 |
Greg Charles
Bartender
Joined: Oct 01, 2001
Posts: 2539
|
|
|
This seems to be more a problem of semantics than of Java concepts. "A final class may not have any abstract method(s)," does not mean, "A final class may have abstract method(s)". Those two sentences have opposite meanings. The first is true, and the second is false.
|
 |
Arno Reper
Ranch Hand
Joined: Mar 14, 2006
Posts: 286
|
|
You can't have abstract and final at the same time because you must override the abstract method and a final class can't be overriden...it's like writing final abstract class...non sense :-) final class A{ abstract void myA(); } The compiler isn't very happy... "A is not abstract and does not override abstract method myA() in A final class A{ ^ 1 error"
|
The man who makes no mistakes does not usually make anything<br /> <br />>>> SCJP 5.0 >> SCJD B&S <<< In progress
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
Originally posted by Edisandro Bessa: ...Once you declared a method as abstract, the compiler obligates you to declare the entire class as abstract. So a final class containing an abstract method would be forced to be declared as final abstract class MyClass which for sure is illegal.
This is exactly right. If you declare an abstract method without declaring the class as abstract, you get the error, "ClassName is not abstract and does not override abstract method methodName..." But then if you declare the final class as abstract, you get the error, "illegal combination of modifiers: abstract and final..."
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
As Greg suggested, this seems to be a semantics issue. Perhaps you're reading this as, "A final class might not have any abstract methods." This is still a true statement. But you could be interpreting this to imply that a final class typically does have abstract methods, although it's not required to (i.e., it "might not"). This would be a misinterpretation from reading too much into the statement. Better wording might have been: "A final class cannot have any abstract methods." This is (clearly?) true.
|
 |
rajeshwar Rao
Ranch Hand
Joined: Mar 20, 2006
Posts: 31
|
|
|
Thanks every one for correcting me. Dont mind i did not think it in depth as i was a little bit curious to give answer quickly
|
 |
 |
|
|
subject: Question is ambigitive
|
|
|