Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

abstract class with final?  RSS feed

 
somin bhuvan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I wanna know the reason, why final keyword cannot be given in the abstract class.

Example:- abstract final class Sample{}

-bhuvan
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know what final and abstract mean? What would you *do* with a final abstract class?
 
Niyas Ahmed Sheikh
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Abstract methods are methods that should be overridden by the subclass. If you want a method to be abstract, then we should have to mark class also abstract. We can mix the abstarct anf non-abstract methods within the abstract class.

Whereas, final is a keywod used in three place: class, methods and variable.
If a class is marked as final, then it can't inherit. i.e., can't extend.
If a method is marked as final, then it can't be overridden.
If a variable is marked as final, then it's value can't be changed.

Now relate your question with the above mentioned thing. Hope u will get the answer.

I am also new to java and I am in learning curve. pls if I mentioned anything wrong, pls point out. Since this should not lead to wrong explanation for newbies.

Regards,
Niyas
 
somin bhuvan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are absolutly correct thanx for ur answer.

-bhuvan
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!