-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOOPS.java
151 lines (135 loc) · 3.73 KB
/
OOPS.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
public class OOPS {
public static void main(String args[]) {
// // Pen p1 = new Pen(); // created a pem object
// p1.setcolor("blue"); // setter
// System.out.println(p1.getcolor()); // getter
// p1.settip(5); // setter
// System.out.println(p1.gettip()); // getter
// Bankdetails bc = new Bankdetails();
// bc.username = "palak chaubey";
// // bc.password=5;
// Student s1 = new Student();
// s1.name = "arya";
// s1.roll = 123;
// s1.password = "abcd";
// s1.marks[0] = 100;
// s1.marks[1] = 90;
// s1.marks[2] = 80;
// Student s2 = new Student(s1);
// s2.password = "xyz";
// s1.marks[2] = 69;
/*
* Student s2 = new Student("rishi");
* System.out.println(s2.name);
* Student s3 = new Student(29);
* System.out.println(s3.roll);
*
*
* for (int i = 0; i < 3; i++) {
* System.out.println(s2.marks[i]);
* }
*
* public static void main(String args[]) {
* Horse h = new Horse();
* h.eats();
* h.walk();
* System.out.println(h.color);
* chicken c = new chicken();
* c.eats();
* c.walk();
*
* }
* }
*
* abstract class Animals {
* String color;
*
* Animals() {
* color = "brown";
* }
*
* void eats() {
* System.out.println("animal eats");
* }
*
* abstract void walk();
* }
*
* class Horse extends Animals {
* void changecolor() {
* color = "dark brown";
* }
*
* void walk() {
* System.out.println("walks on four legs");
* }
* }
*
* class chicken extends Animals {
* void changecolor() {
* color = "yellow";
* }
*
* void walk() {
* System.out.println("walks on two legs");
* }
* }
*
* class Student {
* String name;
* int roll;
* String password;
* int marks[];
*
* /*
* Student(Student s1) { // copy constructer (SHALLOW COPY)
* marks = new int[3];
* this.name = s1.name;
* this.roll = s1.roll;
* this.marks = s1.marks;
* }
*/
// DEEP COPY CONSTRUCTER
// Student(Student s1) {
// marks = new int[3];
// this.name = s1.name;
// this.roll = s1.roll;
// for (int i = 0; i < marks.length; i++) {
// this.marks[i] = s1.marks[i];
// }
// }
// Student() { // non-paramatrised constructer
// marks = new int[3];
// System.out.println("constructer is called...");
// }
// Student(String name) { // paramatrised constructor
// marks = new int[3];
// this.name = name;
// }
// Student(int roll) { // paramatrised constructor
// marks = new int[3];
// this.roll = roll;
// }
// }
// class Bankdetails {
// public String username = "Rishi Chaubey";
// // private long password = 9914;
// }
// class Pen {
// private String color;
// private int tip;
// String getcolor() {
// return this.color; // this keyword
// }
// int gettip() {
// return this.tip;
// }
// void setcolor(String newcolor) {
// color = newcolor;
// }
// void settip(int newtip) {
// tip = newtip;
// }
// }
}
}