Consider the following class Grade: public class Grade { private char letterGrad
ID: 3663499 • Letter: C
Question
Consider the following class Grade:
public class Grade
{
private char letterGrade;
public Grade( char 1g )
{
letterGrade = 1g;
}
public char getLetterGrade( )
{
return letterGrade;
}
public void setLetterGrade( char 1g)
{
letterGrade = 1g;
}
}
In the main method of the class GradeClient, you have coded: Grade g = new Grade ( "A" ); //line 10
When you compile, you get the following message:
GradeClient.java:10: error: incompatible types: String cannot be converted to char
Grade g = new Grade ( "A" ); // line 10
Note: Some messages have been simplified; recompile with -Xdiags: verbose to get full output
1 error
Explain what the problem is and how to fix it.
Explanation / Answer
Regarding the compilation error "string cannot be converted to char",
it's because in the line Grade g = new Grade( "A" ); you used double quotes in the parameter to the constructor. Using double quotes means you are defining a String. However, in the constructor, you defined the parameter as char. If you want to use char as a parameter, then you should use single quotes when instantiating the Grade
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.