Created
February 21, 2021 20:20
-
-
Save kshitijvarshne1/a8bbbce41ba873e6dd06494249d987be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Created by IntelliJ IDEA. | |
* Author: Kshitij Varshney (kshitijvarshne1) | |
* Date: 22-Feb-21 | |
* Time: 12:29 AM | |
* File: Execution.java | |
*/ | |
package feb22_21; | |
import feb22_21.Person.FootballPlayer; | |
import feb22_21.Person.Height; | |
import feb22_21.Person.OffensiveLine; | |
public class Execution { | |
public static void main(String[] args) { | |
FootballPlayer footballPlayer= new FootballPlayer(new Height(5)); | |
System.out.println(footballPlayer); | |
OffensiveLine offensiveLine= new OffensiveLine(new FootballPlayer("Ronaldo",new Height(21))); | |
System.out.println(offensiveLine); | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package feb22_21; | |
public interface Person { | |
// create 3 attribute in the Person Interface | |
String firstName=null; | |
String lastName=null; | |
String Color=null; | |
//create a method toString which has no method | |
public String toString(); | |
//create a new class Height | |
class Height{ | |
// having a attribute height of integer type | |
public int height; | |
//Constructor of Height class | |
public Height(int height) { | |
this.height = height; | |
} | |
public int getHeight() { | |
return height; | |
} | |
public void setHeight(int height) { | |
this.height = height; | |
} | |
@Override | |
public String toString() { | |
return "Height :- "+this.height; | |
} | |
} | |
// Create a new Class 'FootballPlayer' which is implements from Person class | |
// Override the all methods of the Person class | |
class FootballPlayer implements Person { | |
public String name; | |
public Height height; | |
public FootballPlayer(Height height) { | |
this.height = height; | |
this.name="Messi"; | |
} | |
public FootballPlayer(String name, Height height) { | |
this.name = name; | |
this.height = height; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public Height getHeight() { | |
return height; | |
} | |
public void setHeight(Height height) { | |
this.height = height; | |
} | |
//Override the toString method from the Person class | |
@Override | |
public String toString() { | |
return this.name+" "+this.height; | |
} | |
} | |
// create a OffensiveLine having a attribute footballType of type FootballPlayer type | |
class OffensiveLine{ | |
public FootballPlayer footballPlayer; | |
// constructor | |
public OffensiveLine(FootballPlayer footballPlayer) { | |
this.footballPlayer = footballPlayer; | |
} | |
public FootballPlayer getFootballPlayer() { | |
return footballPlayer; | |
} | |
public void setFootballPlayer(FootballPlayer footballPlayer) { | |
this.footballPlayer = footballPlayer; | |
} | |
@Override | |
public String toString() { | |
return "Name :- "+this.footballPlayer; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment