Skip to content

Commit 86b8ba0

Browse files
author
Ram swaroop
committed
added + modified content
1 parent fd906cf commit 86b8ba0

4 files changed

Lines changed: 36 additions & 5 deletions

File tree

_posts/2015-05-14-variables.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,45 @@
11
---
22
layout: post
33
title: Variables
4-
published: false
54
---
65

76
Variables can be broadly classified in to 2 types in Java:
87

9-
1. Instance variables (declared in a class).
10-
2. Local variables (declared inside a method).
8+
1. __Instance__ variables (declared in a class).
9+
2. __Local__ variables (declared inside a method).
10+
11+
Instance variables and objects reside in heap whereas local variables reside in stack. Consider the below program:
12+
13+
{% highlight java linenos %}
14+
class Collar {
15+
}
16+
17+
class Dog {
18+
Collar c; // instance variable
19+
String name; // instance variable
20+
21+
public static void main(String[] args) {
22+
Dog d; // local variable: d
23+
d = new Dog();
24+
d.go(d);
25+
}
26+
27+
void go(Dog dog) { // local variable: dog
28+
c = new Collar();
29+
dog.setName("Aiko");
30+
}
31+
32+
void setName(String dogName) { // local var: dogName
33+
name = dogName;
34+
// do more stuff
35+
}
36+
}
37+
{% endhighlight %}
38+
39+
For the above program, the instance variables, objects and local variables will be stored in memory as shown in the
40+
figure below:
41+
42+
![](/img/posts/variables.png)
1143

12-
Instance variables and objects reside in heap whereas local variables reside in stack.
1344

1445

_posts/2015-05-25-object-oriented-design.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ In OO, the concept of _IS-A_ is based on __class inheritance or interface implem
4444

4545
For example in the below figure:
4646

47-
![](/img/posts/IS-A.png)
47+
![](/img/posts/is-a.png)
4848

4949
_"Car extends Vehicle" means "Car IS-A Vehicle."<br/>
5050
"Subaru extends Car" means "Subaru IS-A Car."_

img/posts/IS-A.png

9.22 KB
Loading

img/posts/variables.png

167 KB
Loading

0 commit comments

Comments
 (0)