Commit 8b0fa3ca authored by Suresh Kumar's avatar Suresh Kumar

Refactor Inheritance

parent c8b50e84
package aggregation.com;
public class Address {
int House_no;
int hno;
String city;
String country;
Address(int h, String c, String cntry){
this.House_no=h;
this.hno=h;
this.city=c;
this.country=cntry;
}
......
......@@ -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.Display();
emp1.display();
}
}
......@@ -3,21 +3,21 @@ package aggregation.com;
public class Employee {
int id;
String name;
Address Add;
Address add;
Employee(int i, String n, Address a){
this.id = i;
this.name=n;
this.Add=a;
this.add=a;
}
void Display(){
void display(){
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................................(" + Add.city + ")\n" +
"your Country Name is..................................(" + Add.country + ") \n " );
"Your House _No Is ...........................(" + add.hno + ")\n" +
"Your City Name is................................(" + add.city + ")\n" +
"your Country Name is..................................(" + add.country + ") \n " );
System.out.print("------------------------Composition With Aggregation------------------------");
......
package association.com;
public class Addres {
int HouseNo;
int hno;
int zip;
String city;
String country;
Addres(int HouseNo, int zip, String city, String country){
this.HouseNo=HouseNo;
Addres(int hno, int zip, String city, String country){
this.hno=hno;
this.zip=zip;
this.city=city;
this.country= country;
......
......@@ -10,7 +10,7 @@ public class Person {
void display(){
System.out.println("Your Name Name is Mr........ (" + name + ")\n" +
"Your House No is .........................(" + add.HouseNo + ")\n" +
"Your House No is .........................(" + add.hno + ")\n" +
"Your Zip Code is ...........................(" + add.zip + ")\n" +
"Your City Name is...........................(" + add.city + ")\n" +
"your Country Name is..................................(" + add.country + ") \n " );
......
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;
}
}
}
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;
}
......
......@@ -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 ................");
}
}
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment