Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Class Attributes | Classes & Objects
Object-Oriented Programming in JavaScript

book
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;
}
1234
class Rectangle{ height; width; }
copy

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;
}
1234
class Student{ name; university; }
copy
Tâche

Swipe to start coding

Add more attributes to the class Student: age and gpa variables.

Solution

class Student{
name;
university;
age;
gpa;
}

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 2
class Student{
name;
university;
// put your code here
}

Demandez à l'IA

expand
ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

some-alt