Answer the question
In order to leave comments, you need to log in
Inheritance error?
class Man{ //суперкласс
protected String name;
protected int age;
Man(String name, int age){
this.name=name;
this.age=age;
}
String getName(){
return name;
}
int getAge(){
return age;
}
public void tellAboutYourself(){
System.out.println("Name: " + name);
System.out.println("Age: " + age);
}
}
class Worker extends Man{ //подкласс
protected int number;
protected String email;
Worker(String name, int age, int number, String email){
super(name, age);
this.number=number;
this.email=email;
}
void work(){
System.out.println("I'm working.");
}
public void tellAboutYourself(){
System.out.println("Number: " + number);
System.out.println("email: " + email);
System.out.println("name: " + name);
System.out.println("age: " + age);
}
}
//использует методы классов Man и Worker
class Program{
public void objects(){
Man men = new Man(); //ошибка
Worker worker = new Worker();
men.tellAboutYourself();
worker.tellAboutYourself();
worker.work();
}
}
Answer the question
In order to leave comments, you need to log in
The problem is in the constructor call (there is no such constructor):
Man men = new Man(); //error
Create a default constructor
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question