If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

It doesn't work. Is there a way to make it work like the way I have in my code? Because there is more then 1 extended class and I want to be able to use the same variable for everything thats in all extended classes.

Still the same thing: you have to instantiate the class that has the method you want to use.

The bigger question might then be, what exactly do you want to accomplish with these 3 classes? Maybe what you really want to do is override the main::one() method instead of creating differently named methods in each child class? (Just a possibility. Without knowing what the actual functionality is that you want to accomplish with these simple example classes, I'm only guessing.)

It's still hard to say without really understanding the underlying requirements driving the design. Essentially, you have two options: inheritance or composition. If class second represents a more specific type of class main, then inheritance probably makes sense, so second could extend main, inheriting all of main's methods, overriding some of them as needed, as well as defining additional methods if that makes sense. Therefore, you use "extends" when the child class "is a" particular case of the parent class.

If, on the other hand, main and second represent different types of objects, then one should not inherit from the other. Instead one could "use" the other, either by instantiating it itself, or have the used object passed into it via the client code. In this case, you might have something like: