-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObject.java
328 lines (326 loc) · 17.2 KB
/
Object.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/**
* @NAME- APOORV SHARAT
* CLASS- 10 C
* ROLL NO. 11
*/
import java.util.*;
public class Object
{
/**
* function to display menu
*/
private static void menu()
{
System.out.println(" @@@@@@@@@@@@ ************ @@@@@@@@@@@@ ************* @@@@@@@@@@@@ *************");
System.out.println(" @@@@@@@@@@@@ ************ @@@@@@@@@@@@ ************* @@@@@@@@@@@@ *************");
System.out.println(" @@ @@ ** ** @@ ** @@ **");
System.out.println(" @@ @@ ************ @@ ************* @@ **");
System.out.println(" @@ @@ ************ @@ ************* @@ **");
System.out.println(" @@ @@ ** ** @@ @@ ** @@ **");
System.out.println(" @@@@@@@@@@@@ ************ @@ @@ ************* @@@@@@@@@@@@ **");
System.out.println(" @@@@@@@@@@@@ ************ @@@@@ ************* @@@@@@@@@@@@ **");
System.out.println();
System.out.println();
System.out.println();
System.out.println("############ @@@@@@@@@@@@@ ############ @@@@@@@@@@@ ## ## @@@@@@@@@@@@ ############ @@@@@@@@@@@@@@@");
System.out.println("############ @@@@@@@@@@@@@ ############ @@@@@@@@@@@ ## ## ## @@@@@@@@@@@@ ############ @@@@@@@@@@@@@@@ ");
System.out.println("## ## @@ @@ ## @@ ## ## ## @@ ## @@ @@");
System.out.println("## ## @@ @@ ## @@@@@@@@@@@ ## ## ## @@ ############ @@ @@");
System.out.println("## ## @@@@@@@@@@@@@ ## @@@@@@@@@@@ ## ## ## @@ ############ @@ @@");
System.out.println("## ## @@ @@ ## @@ ## ## ## @@ ## @@ @@ ");
System.out.println("############ @@ @@ ############ @@@@@@@@@@@ ## ## ## @@ ############ @@@@@@@@@@@@@@@");
System.out.println("############ @@ @@ ############ @@@@@@@@@@@ ## ## @@ ############ @@@@@@@@@@@@@@@");
System.out.println();
System.out.println();
System.out.println("====================================================================================================================================================================================");
System.out.println("====================================================================================================================================================================================");
System.out.println();
System.out.println();
System.out.println();
System.out.println("MENU menu MENU menu menu menu MENU MENU MENU MENU");
System.out.println("MENU menu menu MENU MENU menu menu menu MENU menu MENU MENU MENU");
System.out.println("MENU menu menu MENU MENU MENU menu MENU MENU MENU");
System.out.println("MENU menu menu MENU MENU MENU menu MENU MENU MENU");
System.out.println("MENU menu menu MENU MENU menu menu menu MENU menu MENU MENU MENU");
System.out.println("MENU menu menu MENU MENU menu menu menu MENU menu MENU MENU MENU");
System.out.println("MENU menu menu MENU MENU MENU menu MENU MENU MENU");
System.out.println("MENU menu menu MENU MENU MENU menu MENU MENU MENU");
System.out.println("MENU menu menu MENU MENU menu menu menu MENU menu MENU MENU menu menu MENU");
System.out.println("MENU menu MENU MENU menu menu menu MENU menu MENU menu menu MENU");
System.out.println();
System.out.println();
System.out.println();
System.out.println("______________________________________________________________________________________________________________");
System.out.println("______________________________________________________________________________________________________________");
System.out.println();
System.out.println();
System.out.println();
System.out.println("1. Process oriented programming");
System.out.println("2. Object oriented programming");
System.out.println("3. Representing real world in object oriented programming");
System.out.println("4. Concept of class in object oriented programming");
System.out.println("5. Concept of object in object oriented programming");
System.out.println("6. Memory allocation of an object");
System.out.println("7. accessing member of a class using object");
System.out.println("8. accessing member variables and member functions of a class in another class");
System.out.println("9. Controling access to member of a class from another class");
System.out.println("10. Constructor");
System.out.println("0. BACK TO MAIN MENU");
System.out.println();
System.out.println("ENTER YOUR CHOICE (0-10)");
}
/**
* Function to display details of process oriented programming
* meaning
* examples
* limitations
*/
private void process()
{
System.out.println(" PROCESS ORIENTED PROGRAMMING");
System.out.println();
System.out.println();
System.out.println("It is a programming aproach in which importance ios given to step by step method of solving a problem.");
System.out.println();
System.out.println("Example:");
System.out.println("- BASIC");
System.out.println("- COBOL");
System.out.println("- FORTAN");
System.out.println("- PASCAL");
System.out.println("- C");
System.out.println();
System.out.println();
System.out.println(" DRAWBACKS OF PROCESS ORIENTED PROGRAMMING");
System.out.println();
System.out.println("- Data is not given due importance.");
System.out.println("- Difficult to ensure data security.");
System.out.println("- Difficult to model real world situation.");
}
/**
* function to display details of object oriented programming
* meaning
* examples
* advantages
*/
private void object()
{
System.out.println(" OBJECT ORIENTED PROGRAMMING");
System.out.println();
System.out.println();
System.out.println("It is a programming approach in which importance is given to the objects involved in a system rather then step by step method of solving a problem.");
System.out.println();
System.out.println();
System.out.println(" EXAMPLES OF OBJECT ORIENTED PROGRAMMING");
System.out.println();
System.out.println("- C++");
System.out.println("- java");
System.out.println("- C#");
System.out.println("- python");
System.out.println("- ruby");
System.out.println("- SMALL TALK");
System.out.println();
System.out.println();
System.out.println(" ADVANTAGES OF OBJECT ORIENTED PROGRAMMING");
System.out.println();
System.out.println();
System.out.println("- Data is diven due importance.");
System.out.println("- It is easier to ensure data security.");
System.out.println("- It is easier to model real world situation.");
}
/**
* function to represent real world object in object oriented programming
*/
private void represent()
{
System.out.println(" REPRESENTING REAL WORLD OBJECT IN AN OBJECT ORIENTED PROGRAMMING");
System.out.println();
System.out.println();
System.out.println("- If we write a class in an object oriented program to model or represent group of similar object.");
System.out.println("- Characterstics of real objects are represented by member variables.");
System.out.println("- The behavior of real world object is represented by member functions.");
}
/**
* function to display concept of class in object oriented programming
*/
private void concept_class()
{
System.out.println(" CONCTEPT OF CLASS IN OBJECT ORIENTED PROGRAMMING");
System.out.println();
System.out.println();
System.out.println("- A class is a blue print or a prototype that defines the variables and methods that are common to all the objects of a certain kind.");
}
/**
* function to display concept of object in object oriented programming
*/
private void concept_object()
{
System.out.println(" CONCEPT OF OBJECT IN OBJECT ORIENTED PROGRAMMING");
System.out.println();
System.out.println();
System.out.println("- Class is a user defined datagtype.");
System.out.println("- Premitive datatypes are not sufficient to reperesent each and every real world object.,");
System.out.println("- Class with member functions and vartiables represents real world objects.");
System.out.println("- With the help of member variable we represent characterstics.");
System.out.println("- With the help of member functions we represent behavior.");
System.out.println();
System.out.println();
System.out.println(" OBJECT DECLARATION");
System.out.println();
System.out.println(" classname objectname;");
System.out.println("eg: Rectangle r1;");
System.out.println();
System.out.println();
System.out.println(" OBJECT CREATION");
System.out.println();
System.out.println("Alloting space for object in computer's memory is called object creation.");
System.out.println("eg: r1= new Rectangle();");
}
/**
* function to display memory allocation
*/
private void memory()
{
System.out.println(" MEMORY ALLOCATION OF AN OBJECT");
System.out.println();
System.out.println("- Each and every object of a class can rperesent its own values of member variable.");
System.out.println("- Whenever an object is created, a seperate memory space will be alloted to represent valued of member variables.");
System.out.println("- The total memory space alloted will be the sum of individual memory requirements of the menmber variables.");
}
/**
* function to display accessing member of a class using object
*/
private void accessing_member()
{
System.out.println(" ACCESSING MEMBERS OF A CLASS USING AN BOJECT");
System.out.println();
System.out.println("Member variables and member functions can be accessed by an boject by using the dot operator.");
System.out.println();
System.out.println(" objectname.member_variable OR objectname.member_function");
}
/**
* function to display accessing member variables of a class in another class
*/
private void accessing()
{
System.out.println(" ACCESSING MEMBER VARIABLES/FUNCTIONS OF A CLASS IN ANOTHER CLASS");
System.out.println();
System.out.println();
System.out.println(" We can not directly access member variables or member functions of a class in another class. We have to create an object of the class in order to access its members in another class.");
System.out.println();
System.out.println("format:");
System.out.println("objectname.member variable");
System.out.println("objectname.member function");
}
/**
* function to display controling of members of a class in another class
*/
private void control()
{
System.out.println(" ACCESSING MEMBERS OF A CLASS IN ANOTHER CLASS");
System.out.println();
System.out.println();
System.out.println("- In java access modifiers are used to control the accessing of members of one class in another class.");
System.out.println("- In java there are 4 different access levels. they are:");
System.out.println();
System.out.println("i. private access level:");
System.out.println("- It is the most restrective access level in java.");
System.out.println("- Members of a class with private access levels can be used only within the class.");
System.out.println();
System.out.println("ii. package access levels");
System.out.println("- It is default access level in java.");
System.out.println("- If no access level is mentioned then the members becomes package access levels.");
System.out.println("- members with package access levels can be used in the same class as well as the class in same package.");
System.out.println();
System.out.println("iii. protected access level");
System.out.println("Work under construction. Sorry for the problem.");
System.out.println();
System.out.println("iv. private access level");
System.out.println("- It is the least restrictive level in java.");
System.out.println("- Members of a class of this access level can be accessed in all the classes as well as in all the packages.");
}
/**
* function to display details of constructors
*/
private void constructor()
{
System.out.println(" CONCTRUCTORS");
System.out.println();
System.out.println("A constructor is a special member function used to initialize an object during object creation.");
System.out.println();
System.out.println(" CHARACTERSTICS OF A FUNCTION:");
System.out.println("- Constructor name should be same as the class name.");
System.out.println("- A constructor have no return type.");
System.out.println("- A constructor is invoked automatically during object creation.");
System.out.println();
System.out.println();
System.out.println(" TYPES OF CONSTRUCTOR:");
System.out.println("i. Default constructor:");
System.out.println("- A constructor without any parameter is called default or non parameterised constructor.");
System.out.println();
System.out.println("ii. Parameterised constructor:");
System.out.println("- Constructor with parameters is called parameterised constructor.");
System.out.println();
System.out.println();
System.out.println("NOTE:");
System.out.println(" If there is only a default constructor in a class then each and every object of class will be based on the initaal value af the same constructor.");
}
/**
* main function
*/
public void main()
{
Scanner sc=new Scanner(System.in);
int ch;
do
{
menu();
ch=sc.nextInt();
switch(ch)
{
case 1: System.out.println('\f');
process();
break;
case 2: System.out.println('\f');
object();
break;
case 3: System.out.println('\f');
represent();
break;
case 4: System.out.println('\f');
concept_class();
break;
case 5: System.out.println('\f');
concept_object();
break;
case 6: System.out.println('\f');
memory();
break;
case 7: System.out.println('\f');
accessing_member();
break;
case 8: System.out.println('\f');
accessing();
break;
case 9: System.out.println('\f');
control();
break;
case 10: System.out.println('\f');
constructor();
break;
case 0: System.out.println('\f');
Main m5=new Main();
m5.main_fn();
break;
default:System.out.println('\f');
System.out.println("invalid choice");
}
if(ch!=0)
{
System.out.println();
System.out.println("Press any key to continue....");
sc.skip("\n");
String tmp=sc.nextLine();
}
}while(ch!=0);
}
}