giri
giri

Reputation: 27199

Why final and abstract only modifiers can be used with a local inner class in java?

HI I like to know why final and abstract modifiers used for local inner class in java.... Can anybody elaborate on this?

Upvotes: 0

Views: 2652

Answers (3)

Gladwin Burboz
Gladwin Burboz

Reputation: 3549

It does not matters if your class is local, inner or top level class. You can use only either of abstract or final modifiers with all of them but not both.

.

When you use abstract modifier for class, it means:

  1. Class is partially implemented and there will be sub-class of this class which will give complete implementation
  2. You cannot instantiate abstract class
  3. You can have zero or more abstract methods in abstract class (abstract method is an method whose implementation is not known)

.

When you use final modifier for class, it means:

  1. Class is fully implemented and there should not be any sub-class of this class.
  2. Modifier final is totally opposite of abstract modifier. Hence for a class, final and abstract modifier cannot be used together.

Reference:

8.1.1.1 abstract Classes:

http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#34944

8.1.1.2 final Classes:

http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#54727

Upvotes: 1

shawnwall
shawnwall

Reputation: 4607

There's a great example of the usage of abstract inner classes at o'reilly, please look at look at the 'hierarchies of inner classes' section:

http://onjava.com/pub/a/onjava/excerpt/HardcoreJava_chap06/index.html

Upvotes: 1

Jay
Jay

Reputation: 5043

Because you can extend an inner class. For detail, read here. You would define final to help the reader understand your code better. You would make abstract inner class for the same reasons you would make a regular abstract class.

Upvotes: 0

Related Questions