-
How to block class inheritance and instances?
I have this:
public class myProgram{
public static void main(String[] args){
System.out.println("Hello everyone!");
}
}
class myInherit extends myProgram{
// Anything
}
class myInstance{
public static myProgram theInstance;
public static getInstance(){
myInstance.theInstance = new myProgram();
}
}
------------------------------------------------
I don't want people to inherit OR make an instance of the class myProgram(). Mainly because it would be pointless! There is nothing inside of the class to use! But it has to be Public so the program can run.
So I had a couple options, but none of them worked 100% (all 50%):
//Problem with this? They can still extend the class!
public abstract class myProgram{ // The abstract would prevent people making instances of this class
public static void main(String[] args){
System.out.println("Hello everyone!");
}
}
//Problem with this? They can still create instances of this class!
public final class myProgram{ // The final would prevent people inheriting this class
public static void main(String[] args){
System.out.println("Hello everyone!");
}
}
------------------------------------------------
Anyone have any suggestions? Thank you for your time!
-
a final class with a private constructor, can be neither instantiated, nor extended. it's a lot of effort for nothing though..
-
Thank you cjard!
"it's a lot of effort for nothing though.."
Yes, that is true lol
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks