-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjectsandclass.js
More file actions
35 lines (30 loc) · 1.33 KB
/
Copy pathobjectsandclass.js
File metadata and controls
35 lines (30 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//Object oriented Programming Language(OOPS Concept)
//5 cars -> brand, color, mileage
//entity -> 5 (objects)
//Cars -> class ::: Collection of objects are class
//Objects
//Class
//Abstraction - To hide the internal process and shows only outcome
//Encapsulation - Wrapping of data and it's functionality into a single unit
//inheritance - class A :::data, display() ==> class B reuses
//polymorphism - ability to take more than 1 form of action, ex: add -> 2 numbers, 3 numbers
//add(2 numbers)
//add(3 numbers)
//another example:
//--> 1 parameter ::: circle radius :::3.4*radius*radius
//2 parameter:::rectangle length, breadth:::length*breadth
//3 parameter::: 3 sides of triangle:::length*breadth*height
class car{
constructor(name){ //constructors are the special functions created as part of the class to help to create objects
this.name=name;//to distinguish the value of the attributes of a class, 'this' keyword ios used.
}
//the keyword 'function' is not necessary for a function inside a class, please refer the below function 'display'
display(){
console.log(this.name);
}
}
//To create objects, use const
const colour1 = new car("black");//interpretor look for the value of colour(attribute) in the constructor of the class
const colour2 = new car("White");
console.log(colour1.name);
colour1.display();