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:
9
1
2
3
4
class Rectangle{
height;
width;
}
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.
9
1
2
3
4
class Student{
name;
university;
}
1234class Student{ name; university; }
Tâche
Swipe to start coding
Add more attributes to the class Student
: age
and gpa
variables.
Solution
9
1
2
3
4
5
6
class Student{
name;
university;
age;
gpa;
}
Tout était clair ?
Merci pour vos commentaires !
Section 1. Chapitre 2
9
1
2
3
4
5
class Student{
name;
university;
// put your code here
}
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion