• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Restriction on parent class

 
faisal hameed
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//can we apply restriction on parent class that he cannot creat object of shape type
 
Rakesh Enoch
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make Shape an Interface. Let other classes implement it. This way you cannot intantiate Shape Class.
 
Rob Spoor
Sheriff
Pie
Posts: 20745
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if you can't make it an interface, make it abstract. An abstract class does not need to have any abstract methods, so all you need to do is add the abstract modifier to the class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic