Commit 64bd516f authored by Suresh Kumar's avatar Suresh Kumar

Inheritance

parent 6c965654
package MultipleInterface.com;
interface Printable{
default public void showdata(){
System.out.println("Hi I Am Method Of Printable Interface");
}
}
interface Showable{
default public void showdata(){
System.out.println("Hi I am Method of Showable Interfae ");
}
}
public class Priority implements Printable , Showable{
public static void main(String [] args){
Printable printable = new Priority();
Showable showable = new Priority();
// printable.showdata();
showable.showdata();
}
public void showdata(){
Showable.super.showdata();
}
}
package aggregation.com;
public class Address {
int hno;
String city;
String country;
Address(int h, String c, String cntry){
this.hno=h;
this.city=c;
this.country=cntry;
}
}
package aggregation.com;
public class Aggregat {
public static void main(String [] args){
Address adOjb = new Address(150, "Umerkot", "Pakistan");
Employee emp1 = new Employee(1, "Suresh", adOjb);
emp1.display();
}
}
package aggregation.com;
public class Employee {
int id;
String name;
Address add;
Employee(int i, String n, Address a){
this.id = i;
this.name=n;
this.add=a;
}
void display(){
System.out.println("Your Id Number is .................. (" + id + ")\n" +
"Your Name is .........................(" + name + ")\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 hno;
int zip;
String city;
String country;
Addres(int hno, int zip, String city, String country){
this.hno=hno;
this.zip=zip;
this.city=city;
this.country= country;
}
}
package association.com;
public class Associat {
public static void main(String [] args){
Addres add = new Addres (152, 15334, "Umerkot Sindh" , "Pakistan");
Person emp1 = new Person("Suresh Kumar", add);
emp1.display();
}
}
package association.com;
public class Person {
String name;
Addres add;
Person(String name, Addres add){
this.name = name;
this.add = add;
}
void display(){
System.out.println("Your Name Name is Mr........ (" + name + ")\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 " );
System.out.print("------------------------Compositin With Association-------------------------");
}
}
package composition.com;
public class Car {
private final String name;
private final Engine engine;
public Car(String name , Engine engine){
this.name =name;
this.engine = engine;
}
public String getName(){
return name;
}
public Engine getEngine(){
return engine;
}
}
package composition.com;
public class Compos {
public static void main (String [] args){
Engine engn = new Engine("Petrol" , 500);
Car cr = new Car("Fortuner", engn);
System.out.println("Name Of Vehicle............(" + cr.getName() + ")\n"+
"Of engine is.....................("+ engn.getType() + ")\n"+ "HorsePower Of Engine..................("+ engn.getHp() + ")\n");
System.out.println("--------------------Composition---------------------");
}
}
package composition.com;
public class Engine {
private String type ;
private int hp;
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;
}
}
package inheritancetype;
class Parent{
void eat(){
System.out.println("Eating..........");
};
}
class Child_1 extends Parent{
void name_1(){
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 ................");
}
}
package inheritancetype;
class GrandFather{
void drink(){System.out.println("Drinking..");}
}
class Father extends GrandFather{
void eat(){System.out.println("Eating...");}
}
class Son extends Father{
void speak(){System.out.println("Speaking...");}
}
public class Multilevel{
public static void main(String [] args){
Son b=new Son();
b.drink();
b.eat();
b.speak();
System.out.println("Hi This is Multi Level Inheritance");
}
}
\ No newline at end of file
package inheritancetype;
class Animal{
void drink(){System.out.println("Drinking..");}
}
class Dog extends Animal{
void bark(){System.out.println("Barking...");}
}
public class Single {
public static void main(String [] args){
Dog d=new Dog();
d.bark();
d.drink();
System.out.println("Hi This is Single Level Inheritance");
}
}
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