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:
1234class 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.
1234class Student{ name; university; }
Swipe to start coding
Add more attributes to the class Student
: age
and gpa
variables.
Lösning
Tack för dina kommentarer!
single
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Awesome!
Completion rate improved to 7.69Awesome!
Completion rate improved to 7.69
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:
1234class 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.
1234class Student{ name; university; }
Swipe to start coding
Add more attributes to the class Student
: age
and gpa
variables.
Lösning
Tack för dina kommentarer!
single
Awesome!
Completion rate improved to 7.69
Class Attributes
Svep för att visa menyn
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:
1234class 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.
1234class Student{ name; university; }
Swipe to start coding
Add more attributes to the class Student
: age
and gpa
variables.
Lösning
Tack för dina kommentarer!