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
Hide 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
;
package
aggregation
.
com
;
public
class
Address
{
public
class
Address
{
int
House_
no
;
int
h
no
;
String
city
;
String
city
;
String
country
;
String
country
;
Address
(
int
h
,
String
c
,
String
cntry
){
Address
(
int
h
,
String
c
,
String
cntry
){
this
.
House_
no
=
h
;
this
.
h
no
=
h
;
this
.
city
=
c
;
this
.
city
=
c
;
this
.
country
=
cntry
;
this
.
country
=
cntry
;
}
}
...
...
Inheritance/src/aggregation/com/Aggregat.java
View file @
8b0fa3ca
...
@@ -6,6 +6,6 @@ public static void main(String [] args){
...
@@ -6,6 +6,6 @@ public static void main(String [] args){
Address
adOjb
=
new
Address
(
150
,
"Umerkot"
,
"Pakistan"
);
Address
adOjb
=
new
Address
(
150
,
"Umerkot"
,
"Pakistan"
);
Employee
emp1
=
new
Employee
(
1
,
"Suresh"
,
adOjb
);
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;
...
@@ -3,21 +3,21 @@ package aggregation.com;
public
class
Employee
{
public
class
Employee
{
int
id
;
int
id
;
String
name
;
String
name
;
Address
A
dd
;
Address
a
dd
;
Employee
(
int
i
,
String
n
,
Address
a
){
Employee
(
int
i
,
String
n
,
Address
a
){
this
.
id
=
i
;
this
.
id
=
i
;
this
.
name
=
n
;
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"
+
System
.
out
.
println
(
"Your Id Number is .................. ("
+
id
+
")\n"
+
"Your Name is .........................("
+
name
+
")\n"
+
"Your Name is .........................("
+
name
+
")\n"
+
"Your House _No Is ...........................("
+
Add
.
House_
no
+
")\n"
+
"Your House _No Is ...........................("
+
add
.
h
no
+
")\n"
+
"Your City Name is................................("
+
A
dd
.
city
+
")\n"
+
"Your City Name is................................("
+
a
dd
.
city
+
")\n"
+
"your Country Name is..................................("
+
A
dd
.
country
+
") \n "
);
"your Country Name is..................................("
+
a
dd
.
country
+
") \n "
);
System
.
out
.
print
(
"------------------------Composition With Aggregation------------------------"
);
System
.
out
.
print
(
"------------------------Composition With Aggregation------------------------"
);
...
...
Inheritance/src/association/com/Addres.java
View file @
8b0fa3ca
package
association
.
com
;
package
association
.
com
;
public
class
Addres
{
public
class
Addres
{
int
HouseN
o
;
int
hn
o
;
int
zip
;
int
zip
;
String
city
;
String
city
;
String
country
;
String
country
;
Addres
(
int
HouseN
o
,
int
zip
,
String
city
,
String
country
){
Addres
(
int
hn
o
,
int
zip
,
String
city
,
String
country
){
this
.
HouseNo
=
HouseN
o
;
this
.
hno
=
hn
o
;
this
.
zip
=
zip
;
this
.
zip
=
zip
;
this
.
city
=
city
;
this
.
city
=
city
;
this
.
country
=
country
;
this
.
country
=
country
;
...
...
Inheritance/src/association/com/Person.java
View file @
8b0fa3ca
...
@@ -10,7 +10,7 @@ public class Person {
...
@@ -10,7 +10,7 @@ public class Person {
void
display
(){
void
display
(){
System
.
out
.
println
(
"Your Name Name is Mr........ ("
+
name
+
")\n"
+
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 Zip Code is ...........................("
+
add
.
zip
+
")\n"
+
"Your City Name is...........................("
+
add
.
city
+
")\n"
+
"Your City Name is...........................("
+
add
.
city
+
")\n"
+
"your Country Name is..................................("
+
add
.
country
+
") \n "
);
"your Country Name is..................................("
+
add
.
country
+
") \n "
);
...
...
Inheritance/src/composition/com/Car.java
View file @
8b0fa3ca
package
composition
.
com
;
package
composition
.
com
;
public
class
Car
{
public
class
Car
{
private
final
String
name
;
private
final
String
name
;
private
final
Engine
engine
;
private
final
Engine
engine
;
public
Car
(
String
name
,
Engine
engine
){
public
Car
(
String
name
,
Engine
engine
){
...
@@ -11,9 +10,7 @@ public class Car {
...
@@ -11,9 +10,7 @@ public class Car {
public
String
getName
(){
public
String
getName
(){
return
name
;
return
name
;
}
}
public
Engine
getEngine
(){
public
Engine
getEngine
(){
return
engine
;
return
engine
;
}
}
}
}
Inheritance/src/composition/com/Engine.java
View file @
8b0fa3ca
package
composition
.
com
;
package
composition
.
com
;
public
class
Engine
{
public
class
Engine
{
private
String
type
;
private
String
type
;
private
int
hp
;
private
int
hp
;
...
@@ -7,18 +6,15 @@ Engine(String type , int hp){
...
@@ -7,18 +6,15 @@ Engine(String type , int hp){
this
.
type
=
type
;
this
.
type
=
type
;
this
.
hp
=
hp
;
this
.
hp
=
hp
;
}
}
public
void
setType
(
String
type
)
{
public
void
setType
(
String
type
)
{
this
.
type
=
type
;
this
.
type
=
type
;
}
}
public
String
getType
()
{
public
String
getType
()
{
return
type
;
return
type
;
}
}
public
void
setHp
(
int
hp
)
{
public
void
setHp
(
int
hp
)
{
this
.
hp
=
hp
;
this
.
hp
=
hp
;
}
}
public
int
getHp
()
{
public
int
getHp
()
{
return
hp
;
return
hp
;
}
}
...
...
Inheritance/src/inheritancetype/Hierarchical.java
View file @
8b0fa3ca
...
@@ -10,20 +10,16 @@ class Parent{
...
@@ -10,20 +10,16 @@ class Parent{
System
.
out
.
println
(
"Hi I am Child_1........"
);
System
.
out
.
println
(
"Hi I am Child_1........"
);
}
}
}
}
class
Child_2
extends
Parent
{
class
Child_2
extends
Parent
{
void
name_2
(){
void
name_2
(){
System
.
out
.
println
(
"Hi I am Child_2..........."
);
System
.
out
.
println
(
"Hi I am Child_2..........."
);
}
}
}
}
public
class
Hierarchical
{
public
class
Hierarchical
{
public
static
void
main
(
String
[]
args
){
public
static
void
main
(
String
[]
args
){
Child_2
ch
=
new
Child_2
();
Child_2
ch
=
new
Child_2
();
ch
.
eat
();
ch
.
eat
();
ch
.
name_2
();
ch
.
name_2
();
System
.
out
.
println
(
"Hierarchical Inheritance ................"
);
System
.
out
.
println
(
"Hierarchical Inheritance ................"
);
}
}
}
}
Inheritance/src/inheritancetype/Multilevel.java
View file @
8b0fa3ca
...
@@ -6,7 +6,6 @@ class GrandFather{
...
@@ -6,7 +6,6 @@ class GrandFather{
class
Father
extends
GrandFather
{
class
Father
extends
GrandFather
{
void
eat
(){
System
.
out
.
println
(
"Eating..."
);}
void
eat
(){
System
.
out
.
println
(
"Eating..."
);}
}
}
class
Son
extends
Father
{
class
Son
extends
Father
{
void
speak
(){
System
.
out
.
println
(
"Speaking..."
);}
void
speak
(){
System
.
out
.
println
(
"Speaking..."
);}
}
}
...
@@ -18,5 +17,4 @@ public class Multilevel{
...
@@ -18,5 +17,4 @@ public class Multilevel{
b
.
speak
();
b
.
speak
();
System
.
out
.
println
(
"Hi This is Multi Level Inheritance"
);
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