The below code is showing error i checked lots of time didn't find any error please help me.

class emp{
int id,sal;
String name;

emp(int id,int sal,String name)
{
this.id=id;
this.sal=sal;
this.name=name;
}

void show()
{
System.out.println("Name: "+name);
System.out.println("Salary: "+sal);
System.out.println("ID: "+id);
}
}


class manager extends emp{
int bonus;

manager(int id,int sal,String name,int bonus)
{
this.id=id;
this.sal=sal;
this.name=name;
this.bonus=bonus;
}

}


class inherit{
public static void main(String arg[])
{
emp e1=new emp(1000,58000,"rohit");
manager m1=new manager(1001,98000,"Aman",5000);
e1.show();
m1.show();
}
}

following is error

inherit.java:26: cannot find symbol
symbol : constructor emp()
location: class emp
{
^
1 error

manager(int id,int sal,String name,int bonus){
//Here defaultly emp() default constructor will be called.
this.id=id;
this.sal=sal;
this.name=name;
this.bonus=bonus;
}

emp() default constructor will be called in the above code if you didnt call any base class constructor.
So either pass your arguments by using super(id,sal,name);
which will be matchable for your base class.
or
define emp() default constructor inside of your emp class.

thanks
:-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.