Question
Part A Lets consider the following java class. c lass Student { String name; public i nt grade; // grade between 0 and 100 (condition
Part A
Lets consider the following java class.
class Student
{
String name;
public int grade; // grade between 0 and 100 (condition on Grade);
public void increment ()
{
grade ++;
}
public void decrement ()
{
// (condition on Grade)
grade - -;
}
public int getGrade()
{
return grade;
}
public void setGrade(int G)
{
// (condition on Grade)
grade = g;
}
Public addGrade(int x)
{
// (condition on Grade)
grade +=x;
}
void DisplayGrade()
{
System.out.println ("Grade = +grade);
}
}
Complete the following table
Main function | S1.grade | S2.grade |
Public static void main() { Student s1= new Student(); s1.DisplayGrade() Student s2=new Student(); s1.grade = 59; s1.increment(); s1.increment(); s1.decrement(); s2.addGrade(10); s1.setGrade(55); s1.setgrade(s2.getGrade()); for(int i=1;i<=10:i++) s1.increment(); s2.decrement();
}
|
|
|
Version 2 Here we change grade from public to private public int grade; | S1.grade | S2.grade | Error or remark if any |
public static void main() { Student s1= new Student(); Student s2=new Student(); s1.grade = 59; s1.setgrade(100); s1.incrementgrade(); s2.addgrade(s1.getGrade()); s1.setgrade(0); s1.decrement();
}
|
|
|
|
|
|
|
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started