My query is because I create a subclass (childBook) that extends from the Book class, when I rewrite the constructor in the subclass I get an error, which I do not understand:
Constructor Libro in class libro cannot be applied to given types; requered: boolean, String, String, int, int; found: No arguments; Reason: Actual and formal arguements lists differ in length
The code is as follows:
package ejerciciolibroinfantil;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
* @author jorge
*/
public class EjercicioLibroInfantil {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
// TODO code application logic here
System.out.println("Ingresee los datos correspondientes");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Titulo: ");
String til = br.readLine();
System.out.print("ISBN: ");
String ISBN = br.readLine();
System.out.print("Cantidad de paginas: ");
int numPaginas = Integer.parseInt(br.readLine());
System.out.print("Pagina Actual: ");
int pagAcual = Integer.parseInt(br.readLine());
System.out.print("Edad requerida: ");
int edadRec = Integer.parseInt(br.readLine());
LibroInfantil lib = new LibroInfantil(false, til, ISBN, numPaginas, pagAcual,edadRec);
lib.abierto();
lib.mostrarLibro();
lib.esRecomendable(edadRec);
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ejerciciolibroinfantil;
/**
*
* @author jorge
*/
public class LibroInfantil extends Libro{
private int edadRecomendado = 18;
public LibroInfantil(boolean estado, String titulo, String ISBN,int numPaginas, int pagActual, int edadRec){
this.estado = estado;
this.titulo = titulo;
this.ISBN = ISBN;
this.numPaginas = numPaginas;
this.pagActual = pagActual;
this.edadRecomendado = edadRec;
}
public boolean esRecomendable(int edadNinyo){
if(edadNinyo < 18)
return true;
return false;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ejerciciolibroinfantil;
/**
*
* @author jorge
*/
public class Libro {
protected boolean estado = false;
protected String titulo ="null";
protected String ISBN = "null";
protected int numPaginas = 0;
protected int pagActual = 0;
public Libro(boolean estado, String titulo, String ISBN,int numPaginas, int pagActual){
this.estado = estado;
this.titulo = titulo;
this.ISBN = ISBN;
this.numPaginas = numPaginas;
this.pagActual = pagActual;
}
public void abierto(){
this.estado = true;
System.out.println("Libro abierto");
}
public void cerrado(){
this.estado = false;
System.out.println("Libro cerrado");
}
public void mostrarLibro(){
System.out.println("Titulo del libro: "+titulo+" ISBN: "+ISBN+" Numero de pag: "+numPaginas+" Pagina Actual: "+pagActual);
}
}