Sign in to follow this  
BrianJensen

[?][JAVA] class extends

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this