0

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

Edited by aman rathi: n/a

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by aman rathi
2
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.

Edited by Muralidharan.E: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.