-
Notifications
You must be signed in to change notification settings - Fork 0
/
checking.java
69 lines (45 loc) · 1.35 KB
/
checking.java
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
/******************************************************************************
Online Java Compiler.
Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.
*******************************************************************************/
class one{
//instance variables
int x = 11;
two t; // class tow's reference
//Constructor that recieves two's Constructor
one(two t){
this.t = t;
}
//methods to display class one and class two variables
void display(){
System.out.println("one's x = " +x);
//call class two's methods
t.display();
// access the class two variables
System.out.println("two's variaable = " +t.y);
}
}
class two{
//instance variaable
int y;
//initialize y
two(int y){
this.y = y;
}
//method to display your
void display()
{
System.out.println("two's y= " +y);
}
}
public class checking
{
public static void main(String[] args) {
//create class two's object and then store 22 there
two obj2 = new two(22);
one obj1 = new one(obj2);
//call class one's method
obj1.display();
}
}