-4

We know we can't instantiate an abstract class as it is incomplete. But why can’t we instantiate a class with no abstract methods in it which is marked as abstract? Is there any reason for that?

Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
  • You can using an anonymous instance: `MyAbstract myAbstract = new MyAbstract(){};` – samlewis Jul 15 '15 at 14:59
  • `Is there any reason for that ?` - ain't being *abstract* enough? You mark a class as *abstract* to mark that its instantiation is *prohibited* - IMO it's a quite reasonable reason. –  Jul 15 '15 at 15:07
  • Awesome, never knew that. So, this can be done only in case when we don't have any abstract method in that class, ryt? and thanks for the answer. – user2596752 Jul 15 '15 at 15:07

2 Answers2

0

An abstract class is created for the sole purpose of inheritance. Hence, its instantiation is prohibited weather it has all the required method definitions or not.

Mohit Kanwar
  • 2,962
  • 7
  • 39
  • 59
0

such kind of class may be used as Interface. you should also go through the concept of marker interface

also see What is the use of an empty abstract class?

Community
  • 1
  • 1
Piyush Mittal
  • 1,860
  • 1
  • 21
  • 39