I'm newbie in Java. So question might sound simple, but I'm stuck and can not figure out why I get the error java.lang.String although all I do is just write out the setter and getter normally. So below is my code:
package PerSion;
public class Student extends Persion{
String RollNum, Class;
double Score;
public String getRollNum() {
return this.RollNum;
}
public void setRollNum(String RollNum) {
this.RollNum = RollNum;
}
public String getClass() { //this is where the error show up
return this.Class;
}
public void setClass(String Class) {
this.Class = Class;
}
public double getScore() {
return this.Score;
}
public void setScore(double Score) {
this.Score = Score;
}
public Student() {
}
public Student(String RollNum, String Class, double Score) {
this.RollNum = RollNum;
this.Class = Class;
this.Score = Score;
}
public Student(String RollNum, String Class, double Score, String ID, String Name, String Address, int Age) {
super(ID, Name, Address, Age);
this.RollNum = RollNum;
this.Class = Class;
this.Score = Score;
}
@Override
public void Display() {
System.out.println(RollNum "\t" Name "\t" Class "\t" Score);
}
}
CodePudding user response:
Your problem is that every class already has a final
method called getClass
. You'll have to call your one something else, because you can't have two methods with the exact same name and same parameters in a class, and you can't override a final
method.