I am to create a superclass that has at least two data fields, a constructor and two
other methods. Create two subclasses that inherit from the superclass each
one of which adds at least one more field and at least one more method, one of
which must be an 'over-riding' method. Finally, write an application class that
demonstrates inheritance (creating and using an object from each of the
superclass and subclasses). One of the subclasses objects must use the default
constructor and the other subclass object must use overloading constructor.
I have it started and just about finished(I think) but am unclear if what I am doing is in the right direction.
public class RockBand {
private String instruments;
private int members;
public RockBand() {
instruments = null;
members = 0;
}
public RockBand(String p_Instruments, int p_Members) {
this.instruments = p_Instruments;
this.members = p_Members;
}
public void setInstruments(String p_Instruments) {
instruments = p_Instruments;
}
public void setMembers(int p_Members) {
members = p_Members;
}
public String getInstruments() {
return instruments;
}
public int getMembers() {
return members;
}
}
public class JazzBandsInstruments extends RockBand {
private String Jazz;
public JazzBandsInstruments() {
Jazz = ("Standing Bass, Drums, Saxaphone");
}
@Override
public void setInstruments(String p_Instruments) {
super.setInstruments(p_Instruments);
}
public String getJazz() {
return Jazz;
}
public void setJazz(String Jazz) {
this.Jazz = Jazz;
}
}
public class RockBandsInstruments extends RockBand {
private String instruments;
public RockBandsInstruments() {
}
public RockBandsInstruments(String p_Instruments, int p_Members) {
super(p_Instruments, p_Members);
}
public void setIntruments(String p_Instruments) {
instruments = p_Instruments;
}
public String getIntruments() {
return instruments;
}
}
public class RockersApp {
public static void main(String[] args) {
RockBand roc1 = new RockBand();
roc1.setMembers(4);
System.out.println("Tha band member count is: " + roc1.getMembers());
RockBandsInstruments roc2 = new RockBandsInstruments();
System.out.println("The Rock Bands Instruments are: " + roc2.getIntruments());
JazzBandsInstruments roc3 = new JazzBandsInstruments();
System.out.println("The Jazz Bands instruments are: " + roc3.getJazz());
}
}
Any suggestions, I know it is misses some, but that is why I'm here.
Thanks