Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Assignments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Suresh Kumar
Assignments
Commits
8b0fa3ca
Commit
8b0fa3ca
authored
May 20, 2022
by
Suresh Kumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Inheritance
parent
c8b50e84
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
14 additions
and
27 deletions
+14
-27
Address.java
Inheritance/src/aggregation/com/Address.java
+2
-2
Aggregat.java
Inheritance/src/aggregation/com/Aggregat.java
+1
-1
Employee.java
Inheritance/src/aggregation/com/Employee.java
+6
-6
Addres.java
Inheritance/src/association/com/Addres.java
+3
-3
Person.java
Inheritance/src/association/com/Person.java
+1
-1
Car.java
Inheritance/src/composition/com/Car.java
+1
-4
Engine.java
Inheritance/src/composition/com/Engine.java
+0
-4
Hierarchical.java
Inheritance/src/inheritancetype/Hierarchical.java
+0
-4
Multilevel.java
Inheritance/src/inheritancetype/Multilevel.java
+0
-2
No files found.
Inheritance/src/aggregation/com/Address.java
View file @
8b0fa3ca
package
aggregation
.
com
;
public
class
Address
{
int
House_
no
;
int
h
no
;
String
city
;
String
country
;
Address
(
int
h
,
String
c
,
String
cntry
){
this
.
House_
no
=
h
;
this
.
h
no
=
h
;
this
.
city
=
c
;
this
.
country
=
cntry
;
}
...
...
Inheritance/src/aggregation/com/Aggregat.java
View file @
8b0fa3ca
...
...
@@ -6,6 +6,6 @@ public static void main(String [] args){
Address
adOjb
=
new
Address
(
150
,
"Umerkot"
,
"Pakistan"
);
Employee
emp1
=
new
Employee
(
1
,
"Suresh"
,
adOjb
);
emp1
.
D
isplay
();
emp1
.
d
isplay
();
}
}
Inheritance/src/aggregation/com/Employee.java
View file @
8b0fa3ca
...
...
@@ -3,21 +3,21 @@ package aggregation.com;
public
class
Employee
{
int
id
;
String
name
;
Address
A
dd
;
Address
a
dd
;
Employee
(
int
i
,
String
n
,
Address
a
){
this
.
id
=
i
;
this
.
name
=
n
;
this
.
A
dd
=
a
;
this
.
a
dd
=
a
;
}
void
D
isplay
(){
void
d
isplay
(){
System
.
out
.
println
(
"Your Id Number is .................. ("
+
id
+
")\n"
+
"Your Name is .........................("
+
name
+
")\n"
+
"Your House _No Is ...........................("
+
Add
.
House_
no
+
")\n"
+
"Your City Name is................................("
+
A
dd
.
city
+
")\n"
+
"your Country Name is..................................("
+
A
dd
.
country
+
") \n "
);
"Your House _No Is ...........................("
+
add
.
h
no
+
")\n"
+
"Your City Name is................................("
+
a
dd
.
city
+
")\n"
+
"your Country Name is..................................("
+
a
dd
.
country
+
") \n "
);
System
.
out
.
print
(
"------------------------Composition With Aggregation------------------------"
);
...
...
Inheritance/src/association/com/Addres.java
View file @
8b0fa3ca
package
association
.
com
;
public
class
Addres
{
int
HouseN
o
;
int
hn
o
;
int
zip
;
String
city
;
String
country
;
Addres
(
int
HouseN
o
,
int
zip
,
String
city
,
String
country
){
this
.
HouseNo
=
HouseN
o
;
Addres
(
int
hn
o
,
int
zip
,
String
city
,
String
country
){
this
.
hno
=
hn
o
;
this
.
zip
=
zip
;
this
.
city
=
city
;
this
.
country
=
country
;
...
...
Inheritance/src/association/com/Person.java
View file @
8b0fa3ca
...
...
@@ -10,7 +10,7 @@ public class Person {
void
display
(){
System
.
out
.
println
(
"Your Name Name is Mr........ ("
+
name
+
")\n"
+
"Your House No is .........................("
+
add
.
HouseN
o
+
")\n"
+
"Your House No is .........................("
+
add
.
hn
o
+
")\n"
+
"Your Zip Code is ...........................("
+
add
.
zip
+
")\n"
+
"Your City Name is...........................("
+
add
.
city
+
")\n"
+
"your Country Name is..................................("
+
add
.
country
+
") \n "
);
...
...
Inheritance/src/composition/com/Car.java
View file @
8b0fa3ca
package
composition
.
com
;
public
class
Car
{
private
final
String
name
;
private
final
Engine
engine
;
public
Car
(
String
name
,
Engine
engine
){
...
...
@@ -11,9 +10,7 @@ public class Car {
public
String
getName
(){
return
name
;
}
public
Engine
getEngine
(){
return
engine
;
}
}
}
Inheritance/src/composition/com/Engine.java
View file @
8b0fa3ca
package
composition
.
com
;
public
class
Engine
{
private
String
type
;
private
int
hp
;
...
...
@@ -7,18 +6,15 @@ Engine(String type , int hp){
this
.
type
=
type
;
this
.
hp
=
hp
;
}
public
void
setType
(
String
type
)
{
this
.
type
=
type
;
}
public
String
getType
()
{
return
type
;
}
public
void
setHp
(
int
hp
)
{
this
.
hp
=
hp
;
}
public
int
getHp
()
{
return
hp
;
}
...
...
Inheritance/src/inheritancetype/Hierarchical.java
View file @
8b0fa3ca
...
...
@@ -10,20 +10,16 @@ class Parent{
System
.
out
.
println
(
"Hi I am Child_1........"
);
}
}
class
Child_2
extends
Parent
{
void
name_2
(){
System
.
out
.
println
(
"Hi I am Child_2..........."
);
}
}
public
class
Hierarchical
{
public
static
void
main
(
String
[]
args
){
Child_2
ch
=
new
Child_2
();
ch
.
eat
();
ch
.
name_2
();
System
.
out
.
println
(
"Hierarchical Inheritance ................"
);
}
}
Inheritance/src/inheritancetype/Multilevel.java
View file @
8b0fa3ca
...
...
@@ -6,7 +6,6 @@ class GrandFather{
class
Father
extends
GrandFather
{
void
eat
(){
System
.
out
.
println
(
"Eating..."
);}
}
class
Son
extends
Father
{
void
speak
(){
System
.
out
.
println
(
"Speaking..."
);}
}
...
...
@@ -18,5 +17,4 @@ public class Multilevel{
b
.
speak
();
System
.
out
.
println
(
"Hi This is Multi Level Inheritance"
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment