Witam,
mam problem z dziedziczeniem. W podklasie chcę utworzyć konstruktory+ wywołać w nich konstruktor z nadklasy. Wiem jak mógłbym to zrobić, ale wtedy bardzo dużo niepotrzebnego kodu trzeba napisać.
Jest jakaś możliwość, żeby w podklasie w każdym konstruktorze użyć konstrukcji 'super'? A może coś całkiem innego? Przy 5 parametrach w nadklasie i 3 w podklasie tworzenie konstruktorów zajmuje dużo linii kodu, a to chciałbym ograniczyć do minimum.
Wesołych Świąt!
Tu nadklasa:
public abstract class Book {
private double value;
private int ISBNnumber;
private String title, author, publisher;
public Book(){
this(0000);
}
public Book(int ISBNnumber){
this(ISBNnumber,"TITLE");
}
public Book(int ISBNnumber, String title){
this(ISBNnumber,title,"AUTHOR");
}
public Book(int ISBNnumber, String title, String author){
this(ISBNnumber,title,author,"PUBLISHER");
}
public Book(int ISBNnumber, String title, String author,
String publisher){
this(ISBNnumber,title,author,publisher,9.99);
}
public Book(int ISBNnumber, String title, String author,
String publisher, double value){
this.ISBNnumber=ISBNnumber;
this.title=title;
this.author=author;
this.publisher=publisher;
this.value=value;
}
Tu podklasa:
public class ClassicBook extends Book{
private String binding;
private int pageCount;
private double weight;
public ClassicBook(){
this(100);
}
public ClassicBook(int pageCount){
this(pageCount,1);
}
public ClassicBook(int pageCount,double weight){
this(pageCount,weight,"HARDBACK");
}
public ClassicBook(int ISBNnumber, String title, String author,
String publisher, double value,int pageCount,double weight,String binding){
super(ISBNnumber,title,author,publisher,value);
this.pageCount=pageCount;
this.weight=weight;
this.binding=binding;
}