This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Restriction on parent class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Restriction on parent class" Watch "Restriction on parent class" New topic

Restriction on parent class

faisal hameed
Ranch Hand

Joined: Jan 19, 2009
Posts: 48
//can we apply restriction on parent class that he cannot creat object of shape type

Regards, M Faisal Hameed
PUCIT, Pakistan
Rakesh Enoch

Joined: Jun 27, 2008
Posts: 23
Make Shape an Interface. Let other classes implement it. This way you cannot intantiate Shape Class.

Rakesh Enoch SCJP 1.5 86%
Rob Spoor

Joined: Oct 27, 2005
Posts: 19655

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.

How To Ask Questions How To Answer Questions
wood burning stoves
subject: Restriction on parent class
Similar Threads
Are my classes shaped correctly?
static overloaded methods
Generics: Shape example does not work as SUN says
Whizlabs test question : Generics
Generics Casting