Question: Q1: Consider the following java class: class Student { private int student_Number; private String student_Name; public Student(int stNo,String name) { student_Number=stNo; student_Name=name; } public String
Q1:
Consider the following java class:
class Student { private int student_Number; private String student_Name; public Student(int stNo,String name) { student_Number=stNo; student_Name=name; } public String getName() { return student_Name; } public int getNumber() { return student_Number; } public void setName(String st_name) { student_Name = st_name; } }
- What are the instance variables?
- What are the local variables?
- What are the accessor methods?
- What is the mutator method?
Answer:
Q2:
Consider the following java class:
public class Circle { private double radius; private String color; public Circle(){ radius=0; color = "red"; } public Circle(double r, String c){ radius=r; color = c
} public void setColor(String c){ color = c;
} public double getRadius(){ return radius; } public String getColor(){ return color; } }
Write a Tester class named CircleTester which contains the following instruction:
- Use the first constructor to create a circle object c1.
- Use the second constructor to create a circle object c2 where radius =15, color = Green.
- Use the setColor method to change the color of the circle c1 to Yellow.
- Print the radius and color of circle c2.
Note:
Include the screenshot of the program output as a part of your answer. Otherwise, you will be marked zero for this question.
Answer:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
