public class Person extends Employee{private String firstName;private String lastName;
public Person(String firstName,String lastName){this.firstName=firstName;this.lastName=lastName;}
}
Person is a class which inherits Employee and see the code below where Employee also inherit the Class Person.
In the above code we will see the error message "cyclic inheritance involving Person public class Person extends Employee" Actually Person should be the super class here and Employee is the subclass. But here the relationsship is such that Employee is the subclass of Person, again Person is the subclass of Employee. It's a cyclic inheritance which is not possible. The solution of this problem is identifying the proper relationship i.e, finding out the super class and the subclass. In our case Person is the super class, so it should not try to inherit Employee and Employee is the subclass which will inherit Person. Correction is ommiting "extends Employee" from the Person class signature as below:
Wednesday, August 19, 2009You see this error message because of any one of the followings:
Read More
1. You misspelled the keyword class (fully lower case) or you did not write it at all for writing your class. public Class Test //actual keyword is class In the above example Class (C is in upper case) is written instead of class (fully lower case). 2. Remember you cannot declare variables outside of class body like below. int variable; //variable must be declared inside the class body To solve this declare variables inside the class body as below. public class Test 3. All methods are also defined within the method body. If you define any method outside of the class body you will see this error message. public class Test In the above code, the method anotherMethod is defined after the end of the class. So this error occurred. Most often it occurs just because of incorrect use of {} (curly braces). Check all { are closed with } in the proper place. 4. If you are defining an interface, check you spelled it correctly in fully lowercase. public Interface Test //actual keyword is interface In the above code, keyword interface is misspelled with upper I. 5. Same way if you define an enum spell the keyword enum correctly. public Enum Day //actual keyword is enum In the above example Enum is incorrect as the E is in upper case, it will be lower case e.
Subscribe to:
Posts (Atom)
|