Main.java:3: error: class Person is public, should be declared in a file named Person.javapublic class Person { ^Main.java:15: error: class Student is public, should be declared in a file named Student.javapublic class Student extends Person { ^Main.java:24: error: class Employee is public, should be declared in a file named Employee.javapublic class Employee extends Person { ^Main.java:34: error: class Faculty is public, should be declared in a file named Faculty.javapublic class Faculty extends Employee { ^Main.java:44: error: class Staff is public, should be declared in a file named Staff.javapublic class Staff extends Employee { ^5 errors
Question
Main.java:3: error: class Person is public, should be declared in a file named Person.javapublic class Person { ^Main.java:15: error: class Student is public, should be declared in a file named Student.javapublic class Student extends Person { ^Main.java:24: error: class Employee is public, should be declared in a file named Employee.javapublic class Employee extends Person { ^Main.java:34: error: class Faculty is public, should be declared in a file named Faculty.javapublic class Faculty extends Employee { ^Main.java:44: error: class Staff is public, should be declared in a file named Staff.javapublic class Staff extends Employee { ^5 errors
Solution
The error messages you're seeing are because in Java, each public class should be in its own file. The name of the file should match the name of the public class.
For example, if you have a public class named "Person", it should be in a file named "Person.java".
So, to fix these errors, you should:
- Cut the code for each public class from your "Main.java" file.
- Create a new .java file for each public class. The name of each file should match the name of the public class it contains. For example, you should create a "Person.java" file for the "Person" class, a "Student.java" file for the "Student" class, and so on.
- Paste the code for each public class into its corresponding .java file.
After you've done this, you should be able to compile and run your code without any errors.
Similar Questions
public class Person { }public class Student extends Person { }public class Teacher extends Person { }public class Room { }public class Classroom extends Room { }public class Office extends Room { }public class Hallway extends Room { }public class MainClass { private static ArrayList<Room> layout = new ArrayList<Room>(); public static void main(String[] args) { /* MISSING CODE */ }}
Given the following code, find the compile error. Please select all that apply. public class Test { public static void main(String[] args) { m(new GraduateStudent()); m(new Student()); m(new Person()); m(new Object()); } public static void m(Student x) { System.out.println(x.toString()); } } class GraduateStudent extends Student { } class Student extends Person { @Override public String toString() { return "Student"; } } class Person extends Object { @Override public String toString() { return "Person"; } } Group of answer choicesm(new GraduateStudent()) causes an errorm(new Student()) causes an errorm(new Person()) causes an errorm(new Object()) causes an error
COMPILE TIME ERROR EmployeeIDGeneration/src/UserInterface.java:1: error: class EmployeeIdGenerator is public, should be declared in a file named EmployeeIdGenerator.java public class EmployeeIdGenerator { ^ EmployeeIDGeneration/src/UserInterface.java:4: error: cannot find symbol Scanner sc = new Scanner(System.in); ^ symbol: class Scanner location: class EmployeeIdGenerator EmployeeIDGeneration/src/UserInterface.java:4: error: cannot find symbol Scanner sc = new Scanner(System.in); ^ symbol: class Scanner location: class EmployeeIdGenerator 3 errors
Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone_number, and e-mail address. A student has a status (freshman, sophomore, junior, or senior). An employee has an office, salary. A faculty member has office_hours and a rank. A staff member has a title. Override the toString() method in each of these classes to display their details. Write a Java application and subsequent pseudocode to implement/simulate the same.
COMPILE TIME ERROR StudentDetails/src/UserInterface.java:16: error: constructor Student in class Student cannot be applied to given types; student = new Student(id, name, address); ^ required: int,String,String,String found: int,String,String reason: actual and formal argument lists differ in length 1 error
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.