Creating a class with instance methods
Create a class named Student
with two instance variables: name
of type String
and age
of type int
. Write two instance methods: getName
and getAge
to return the name and age of the student respectively.
20
20
20
16
16
16
17
17
17
Instructor solution
Think you've got it?
What is the purpose of instance methods in a class?
- A.
Instance methods allow objects of a class to perform specific tasks and interact with their data.
- B.
Instance methods are used to define static variables in a class.
- C.
Instance methods are used to create objects of a class.
- D.
Instance methods are used to perform tasks that are not related to objects of a class.
You may exit out of this review and return later without penalty.