Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit161cf30

Browse files
authored
Merge pull request#1 from ismailfaris19/main
object, class and inheritance
2 parents5493897 +16b0ee3 commit161cf30

File tree

2 files changed

+193
-0
lines changed

2 files changed

+193
-0
lines changed

‎ObjectAndClass.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
packageoopsConcepts;
2+
3+
publicclassObjectAndClass {
4+
5+
intemployeeId;
6+
StringemployeeName;
7+
8+
publicObjectAndClass() {
9+
super();
10+
}
11+
12+
publicObjectAndClass(intemployeeId,StringemployeeName) {
13+
super();
14+
this.employeeId =employeeId;
15+
this.employeeName =employeeName;
16+
}
17+
18+
publicvoidmethodInitializer(intid,Stringname) {
19+
employeeId =id;
20+
employeeName =name;
21+
}
22+
23+
publicvoidmethodForAnonymousObject() {
24+
System.out.println("Employee ID: "+employeeId+" is updated successfully.");
25+
}
26+
27+
publicvoiddisplay() {
28+
System.out.println("Employee ID: "+employeeId+" and Employee Name: "+employeeName+" is updated successfully.");
29+
}
30+
31+
32+
publicstaticvoidmain(String[]args) {
33+
34+
ObjectAndClassoc =newObjectAndClass();
35+
36+
//through variable reference
37+
38+
oc.employeeId =1608;
39+
oc.employeeName ="Ismail";
40+
oc.display();
41+
42+
//through method reference
43+
44+
oc.methodInitializer(1608,"Faris");
45+
oc.display();
46+
47+
//through constructor reference
48+
49+
ObjectAndClassoac =newObjectAndClass(1608,"Ismail Faris");
50+
oac.display();
51+
52+
//anonymous object
53+
54+
newObjectAndClass(1608,"Faris").methodForAnonymousObject();
55+
56+
}
57+
58+
}

‎TypesOfInheritance.java

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
packageoopsConcepts;
2+
3+
//IS-A Relationship
4+
5+
//Single Inheritance
6+
7+
//class ParentClass{
8+
//int i = 5;
9+
//int j = 10;
10+
//void sum() {
11+
//int total = i + j;
12+
//System.out.println(total);
13+
//}
14+
//}
15+
//
16+
//class SubClass extends ParentClass{
17+
//void display() {
18+
//System.out.println("problem solved");
19+
//}
20+
//}
21+
//
22+
//public class TypesOfInheritance {
23+
//
24+
//public static void main(String[] args) {
25+
//
26+
//SubClass ps = new SubClass();
27+
//ps.sum();
28+
//ps.display();
29+
//}
30+
//
31+
//}
32+
33+
//Multi Level Inheritance with method overloading and overriding concept
34+
35+
//class ParentClass{
36+
//int i = 5;
37+
//int j = 10;
38+
//void sum() {
39+
//int total = i + j;
40+
//System.out.println(total);
41+
//}
42+
//}
43+
//
44+
//class SubClassOne extends ParentClass{
45+
//void display() {
46+
//System.out.println("From One");
47+
//}
48+
//void display(int k) {
49+
//i = k;
50+
//}
51+
//}
52+
//
53+
//class SubClassTwo extends SubClassOne{
54+
//void display() {
55+
//super.display();
56+
//super.display(5);
57+
//System.out.println("From Two");
58+
//}
59+
//}
60+
//
61+
//public class TypesOfInheritance {
62+
//
63+
//public static void main(String[] args) {
64+
//
65+
//SubClassTwo ps = new SubClassTwo();
66+
//ps.sum();
67+
//ps.display();
68+
//}
69+
//
70+
//}
71+
72+
//Hierarchical Inheritance
73+
74+
//class ParentClass{
75+
//int i = 5;
76+
//int j = 10;
77+
//void sum() {
78+
//int total = i + j;
79+
//System.out.println(total);
80+
//}
81+
//}
82+
//
83+
//class SubClassOne extends ParentClass{
84+
//void display() {
85+
//System.out.println("From One");
86+
//}
87+
//}
88+
//
89+
//class SubClassTwo extends ParentClass{
90+
//void display() {
91+
//System.out.println("From Two");
92+
//}
93+
//}
94+
//
95+
//public class TypesOfInheritance {
96+
//
97+
//public static void main(String[] args) {
98+
//
99+
//SubClassOne so = new SubClassOne();
100+
//so.sum();
101+
//so.display();
102+
//
103+
//SubClassTwo st = new SubClassTwo();
104+
//st.sum();
105+
//st.display();
106+
//}
107+
//}
108+
109+
//HAS-A Relationship
110+
111+
classParentClass{
112+
inti =5;
113+
intj =10;
114+
publicintsum() {
115+
inttotal =i +j;
116+
returntotal;
117+
}
118+
}
119+
120+
classSubClassOne{
121+
ParentClasspc;
122+
publicvoiddisplay() {
123+
pc =newParentClass();
124+
intk =pc.sum();
125+
intmultiply =k *k;
126+
System.out.println(multiply);
127+
}
128+
}
129+
130+
publicclassTypesOfInheritance {
131+
132+
publicstaticvoidmain(String[]args) {
133+
newSubClassOne().display();
134+
}
135+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp