File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Static Inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Static Inheritance" Watch "Static Inheritance" New topic
Author

Static Inheritance

sam backet
Greenhorn

Joined: Sep 02, 2011
Posts: 22

Hello,

I want to implement a static method call like that:



I want to have a mainclass "Help" and many subclasses.

How can I do it.

thanks

sam
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38441
    
  23
That might work, and should give you exactly the same calls as you posted earlier. But you need to ensure that you are not duplicating code in the needHelp() methods.
sam backet
Greenhorn

Joined: Sep 02, 2011
Posts: 22

thats good thanks..

and now I want that the subclasses are outside. maybe in an another package..

sam
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38441
    
  23
You might be better passing the name of the language to the needHelp() methodAnd I think I ought to have made those methods static in my earlier post.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38441
    
  23
sam backet wrote:thats good thanks..

and now I want that the subclasses are outside. maybe in an another package..

sam
You can't have it both ways. You can say Help.Java.something or you can have the JavaHelp class in another package, but not both.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38441
    
  23
Help.Java.something() implies that Java is a nested class inside Help. [If you call an inner class "nested" then it is static.]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38441
    
  23
Sorry I was mistaken about the nomenclature: look here for the correct nomenclature. I meant you would call that nested class static.
sam backet
Greenhorn

Joined: Sep 02, 2011
Posts: 22

I thought, maybe it is possible to work with "extends"

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38441
    
  23
You can of course extend a class, but it seems weird to have a class contain a subclass of itself. Remember Help.Java.something() means Java is a nested static class. You do not have a list of subclasses associated with a superclass, so you can go from subclass to superclass, but not vice versa.
sam backet
Greenhorn

Joined: Sep 02, 2011
Posts: 22

and how can I solve it..my problem is, that if I do, what you say..my main class"help" will be confused.

There are more than 3 innerclasses..and this is not good.. Maybe it works with an other syntax..not only with help.java...

?

thanks

sam
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38441
    
  23
You can of course writeBut static and inheritance don't really sit well together. I still prefer my suggestions with an enum called Language.
sam backet
Greenhorn

Joined: Sep 02, 2011
Posts: 22

thank you.

sam
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38441
    
  23
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static Inheritance