-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCar.java
More file actions
38 lines (27 loc) · 749 Bytes
/
Car.java
File metadata and controls
38 lines (27 loc) · 749 Bytes
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
package JavaSessions;
public class Car {
String name;
int price;
String color;
static int wheels = 4; //common property value
public static void main(String[] args) {
//Object will never hold any static property
//static vars should be access by class name
Car c1 = new Car();
c1.name = "BMW";
c1.price = 70;
c1.color = "White";
Car c2 = new Car();
c2.name = "AUDI";
c2.price = 80;
c2.color = "Red";
Car c3 = new Car();
c3.name = "Honda";
c3.price = 20;
c3.color = "Black";
System.out.println(c1.name + " "+ c1.price + " "+ c1.color +" " + Car.wheels);
System.out.println(c1.wheels);//wrong practice
//static var can be access directly without class name:
System.out.println(wheels);
}
}