Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static Inheritance

 
sam backet
Greenhorn
Posts: 22
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thats good thanks..

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

sam
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought, maybe it is possible to work with "extends"

 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you.

sam
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic