Jump to content
  • Advertisement
Sign in to follow this  
BrianJensen

[?][JAVA] class extends

This topic is 2143 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Why can a class only have one parent but you can chain parents together effectivly doing the same thing like this? Or am I thinking this is doing something that it isn't?

 

public class myFirstClass
{
    public int someFirstInt;
    public myFistClass(int fi)
    {
        someFirstInt = fi;
    }
}
public class mySecondClass extends myFirstClass
{
    public int someSecondInt;
    public mySecondClass(int si, int fi)
    {
        super(fi);
        someSecondInt = si;
    }
}
public class myThirdClass extends mySecondClass
{
    public int someThirdInt;
    public myThirdClass(int ti, int si, int fi)
    {
        super(si, fi);
        someThirdInt = ti;
    }
}
public class myForthClass extends myThirdClass
{
    public int someForthInt;
    public myForthClass(int foi, int ti, int si, int fi)
    {
        super(ti, si, fi);
        someForthInt = foi;
    }
}
myForthClass ChainParent = new myForthClass(1, 1, 1, 1);

does myForthClass effectivly have access to everything in myThirdClass, mySecondClass, and myFirstClass?

Edited by 0Circle0

Share this post


Link to post
Share on other sites
Advertisement
Building on that, a good example is JFrame and applet. You can't extend to both a JFrame and an applet because it is impossible to be both, they both have properties that cannot be shared.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!