-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOOPS.java
More file actions
104 lines (83 loc) · 2.15 KB
/
Copy pathOOPS.java
File metadata and controls
104 lines (83 loc) · 2.15 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package BASICS;
/*
class AsConstructorArg{
Test t;
AsConstructorArg(Test t){
this.t=t;}
void display(){
System.out.println(t.i);}
}
class Test{
int i =10;
Test(){
AsConstructorArg ar = new AsConstructorArg(this);
ar.display();}
public static void main(String[] args){
Test t1 = new Test();
}
}
*/
class test {
static int count;
public test() {
count++;
System.err.println("creating a new object");
}
public test(int val1, int val2){
this (); //calling default constructor
x = val1;
y = val2;
}
void something(int x, int y){
this.x = x;
this.y = y;
}
void walk(){
System.out.println("the value of x is" + x + "and y is " + y);
}
int x;
int y;
int count(int n) {
return n;
}
}
class developer extends test{
public developer(int val1, int val2){
// super(val1, val2);
x = val1;
y = val2;
}
void walk(){
System.out.println("this is developer class walk");
}
}
public class OOPS {
// public void swap(int a, int b) {
// int temp = a;
// a = b;
// b = temp;
// }
public static void main(String[] arg) {
OOPS o = new OOPS(); //create class object to access its functions
test t = new test();
t.x = 10;
t.y = 20;
System.out.println(t.x + " " + t.y);
test t2 = new test(3, 4);
System.err.println(t2.x + " " + t2.y);
// swap(t.x, t.y);
// System.out.println(t.x + " " + t.y);
System.out.println(t.count(5));
System.out.println(test.count);
test t3 = new test();
t3.something(3, 4);
System.err.println(t3.x + " " + t3.y);
System.out.println(test.count);
developer d = new developer(7, 8);
System.out.println(test.count);
System.out.println(d.x + " " + d.y);
d.something(1, 2);
System.out.println(d.x + " " + d.y);
d.walk(); //this will trigger developer class walk, since it exists. if it don't exist, then it will trigger parent class walk
}
}