public class Top{
public int top = 1;
public Top(int top){ this.top = top; }
}
public class Middle extends Top{
public Middle(int top){
super(top);
this.top = this.top + top;
}
}
public class Bottom extends Middle{
public Bottom(){ super(3); }
public Bottom(int top){
super(top);
this.top = top;
}
}
For this class, I'm confused as to why Top t = new Top() is a invalid declaration? Does it have to have a passing argument for this object t being created to be valid?
Why is 1) Top t = new Bottom() and 2) Top t = new Top(3) valid? I'm new to java and Does the bottom class have an empty constructor so 1) is valid?
Also, say for example Top t = new Middle(2), how would I proceed to figure out what t.top without using code? Like the dot operator always throws me off, what I'm thinking is that the object "t" is being associated with the attributes of the top variable? It's supposed to equal 4 but I'm trying to figure this out but these concepts seem so foreign to me right now. Any explanation would be appreciated.