-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariables.java
More file actions
62 lines (50 loc) · 1.12 KB
/
Variables.java
File metadata and controls
62 lines (50 loc) · 1.12 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
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
//Variables
// class Variables
// int age = 20; //Instance Variable
// statc int speed = 70; //static variable
// void method()
// {
// int n = 90; //Local variable
// }
// }
//#####################Local Variable #####################
class Variables
{
public void CarSpeed()
{
int speed = 70; //Local variable speed
System.out.println(speed);
}
public static void main(String[] args)
{
Variables object = new Variables();
object.CarSpeed();
}
}
//#######################Instance Variable ##################
class Variables
{
int speed; //instance variable speed
}
class Run
{
public static void main(String[] args)
{
Variables obj = new Variables();
obj.speed = 20;
System.out.println(obj.speed);
}
}
//####################### Static Variavle ##########################
class Car
{
public static int speed = 20000; //Static variable
}
public class Variables
{
public static void main(String[] args)
{
// Car.speed = 20000; //You can access the static variable without object
System.out.println(Car.speed);
}
}