59.5k views
0 votes
Write a class called Student that has two private data members - the student's name and grade. It should have an init method that takes two values and uses them to initialize the data members. It should have a get_grade method.

1 Answer

4 votes

Answer:

Step-by-step explanation:

The following class is written in Python as it is the language that uses the init method. The class contains all of the data members as requested as well as the init and get_grade method. It also contains a setter method for both data variables and a get_name method as well. The code can also be seen in the attached image below.

class Student:

_name = ""

_grade = ""

def __init__(self, name, grade):

self._name = name

self._grade = grade

def set_name(self, name):

self._name = name

def set_grade(self, grade):

self._grade = grade

def get_name(self):

return self._name

def get_grade(self):

return self._grade

User Midinastasurazz
by
4.4k points