Class Attributes
Attributes are some variables inside the class that describe each object. Letβs demonstrate it with two classes β Rectangle
and Student
.
We can represent Rectangle
by its height and width. Add these Attributes to the class definition:
class Rectangle{ height; width; }
If you need to describe student in some way, you can create class Student
with attributes like, for example, name and university.
class Student{ name; university; }
Task
Swipe to start coding
Add more attributes to the class Student
: age
and gpa
variables.
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 1. ChapterΒ 2