So, not so much a question for a specific project but more for understanding for future.
I don't understand what the daughter class constructors are meant to look like and contain. I understand that the parent class will initialise their attribute and objects of other classes if need be, but when it comes to the daughter class do you initialise the parent class attributes you want to use through the super() function as well as their own attributes?
For example:
public class A{
private int num1;
private int num2;
public A (int num1, int num2){
this.num1 = num1;
this.num2 = num2;
}
}
class B extends A{
private int num3;
private int num4;
public B (int num1, int num2, int num3, int num4){
super(num1, num2);
this.num3 = num3;
this.num4 = num4;
}
}
class C extends A{
private int num5;
private int num6;
public C (int num1, int num2, int num5, int num6){
super(num1, num2);
this.num5 = num5;
this.num6 = num6;
}
}
(Not running code... (I don't think, I'm new to Java)
From my understanding, in both daughter classes i need to initialise the parent classes attributes if I want to access them and then use the whole get and set shebang and then super.method to use them. Where I'm confused is the fact that is this the right way of going about it? Is this completely wrong or am I somewhat on the right track?
I think this is not far off the mark. If you add get/set for num1 and num1 in class A and make them
public, you can call them on the subclasses directly as they are inherited. I.e.would work.