-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClasses and Objects.txt
80 lines (42 loc) · 1.3 KB
/
Classes and Objects.txt
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
public class LPU {
//Primitive Data Types
String name= "abc";
byte a; // 8 bits
short h; //16 bits -32700 to 32700
int b = 2000000000; //32 bits
long c; //64 bits
float d; // 1.232
double e;
char f; //'A' 16 bits
boolean g; //represents true and false
//Reference Data Type
//Objects - String, Array,
//Array
}
class Car{
String color;
String model;
int year;
void drive(){
System.out.println("Moving Forward");
}
void brake(){
System.out.println("Brakes Applied");
}
}
public class Main{
public static void main(String[] args){
Car ferrari = new Car(); // object 1
ferrari.model = "Ferrari";
ferrari.year = 2024;
System.out.println("the car model is : " + ferrari.model + " and year " + ferrari.year);
ferrari.drive(); // called the drive function using the object
ferrari.brake();
Car BMW = new Car(); // object 2
BMW.model = "BMW";
BMW.year = 2025;
System.out.println("the car model is : " + BMW.model + " and year " + BMW.year);
ferrari.drive(); // called the drive function using the object
ferrari.brake();
}
}