
456 CHAPTER 7 Object-Oriented Programming,Part 2: User-Defined Classes
EXERCISES,PROBLEMS, AND PROJECTS
return ( lg ); // line 12
^
2 errors
Explain what the problem is and how to fix it.
52. You coded the following definition for the class Grade:
public class Grade
{
private char letterGrade;
public Grade( char letterGrade )
{
letterGrade = letterGrade;
}
public char getLetterGrade( )
{
return letterGrade;
}
}
In the main method of the class GradeClient, you have coded:
Grade g1 = new Grade( 'A' );
System.out.println( g1.getLetterGrade( ) );
The code compiles properly and runs, but the result is not what
you expected.
The client’s output is a space, not an A.
Explain ...