How to remove the errors in the multi level inheritance in the following Java code? -
i learning multilevel inheritance in java , got stuck in following code.but it's showing 1 error.and there other way doing this.can inheritance while using methods?can help?thanks in advance. error:
shoppingmain.java:27: error: constructor b in class b cannot applied given types; { ^ required: string,int
found: no arguments
reason: actual , formal argument lists differ in length
1 error
class a{ int price; string product; } class b extends { int quantity; int total; b(string a,int b) { product=a; price=b; } void productdetails() { system.out.println("the product name is"+product); system.out.println("the price is"+price); } } class c extends b { c(int c,int d) { //line 27 quantity=c; total=d; } void productcost() { system.out.println("the quantity is"+quantity); system.out.println("the total cost is"+total); } } class shoppingmain { public static void main(string args[]) { b obj1=new b("pen",5); c obj2=new c(2,10); obj1.productdetails(); obj2.productcost(); } }
as have declared constructor in father's class, , inheritance works creating each objects father child, neeed specify parameters create b object, using super keyword in c:
public class c extends b { c(int c, int d) { super("prueba", 1); quantity = c; total = d; } void productcost() { system.out.println("the quantity is" + quantity); system.out.println("the total cost is" + total); } }
Comments
Post a Comment