Skip to content

Instantly share code, notes, and snippets.

@inan-mahmud
Created November 27, 2019 16:14
Show Gist options
  • Save inan-mahmud/c73ab2c25b0778afdaf353449cd8c208 to your computer and use it in GitHub Desktop.
Save inan-mahmud/c73ab2c25b0778afdaf353449cd8c208 to your computer and use it in GitHub Desktop.
Abstraction
public interface ExtraCurriculum {
void debate();
void takeQuiz();
void speech();
}
public class Main {
public static void main(String[] args) {
// write your code here
Teacher teacher = new Teacher("Inan","27");
teacher.printPerson("Inan");
teacher.debate();
teacher.speech();
teacher.takeQuiz();
System.out.println();
System.out.println("---------------------------");
System.out.println();
Student student = new Student("Sayeed","23");
student.printPerson("Sayeed");
student.debate();
student.speech();
student.takeQuiz();
student.carom();
student.run();
student.playTableTennis();
student.playCricket();
student.playFootball();
}
}
abstract public class Person {
private String name;
private String age;
public Person(String name, String age) {
this.name = name;
this.age = age;
}
public static void printName() {
String name = "Inan";
System.out.println(name);
}
abstract void printPerson(String name);
public void showPerson() {
System.out.println("hi i am a person");
}
public final void goThere() {
System.out.println("hey please go there");
}
}
public interface Sports {
void run();
void playTableTennis();
void carom();
}
public class Student extends Person implements ExtraCurriculum, YearlySports {
private String name;
public Student(String name, String age) {
super(name, age);
this.name = name;
}
/**
* abstract class method
* @param name
*/
@Override
void printPerson(String name) {
System.out.println("The students name is "+name);
}
/**
* interface methods
*/
@Override
public void debate() {
System.out.println(this.name+" did a debate on Eve teasing");
}
@Override
public void takeQuiz() {
System.out.println(this.name+" attended quiz on Peripheral");
}
@Override
public void speech() {
System.out.println(this.name+" gave speech on Machine learning");
}
@Override
public void run() {
System.out.println(this.name+" won the 100 meter run");
}
@Override
public void playTableTennis() {
System.out.println(this.name+" placed 2nd");
}
@Override
public void carom() {
System.out.println(this.name+ " defeated sathi mam");
}
@Override
public void playCricket() {
System.out.println(this.name+" won the man of match");
}
@Override
public void playFootball() {
System.out.println(this.name+" won the man of the match");
}
}
public class Teacher extends Person implements ExtraCurriculum {
private String name;
public Teacher(String name, String age) {
super(name, age);
this.name = name;
}
/**
* abstract class method
* @param name
*/
@Override
void printPerson(String name) {
System.out.println("I am a teacher and my name is "+name);
}
/**
* interface methods
*/
@Override
public void debate() {
System.out.println(this.name+" was the judge of the debate");
}
@Override
public void takeQuiz() {
System.out.println(this.name+" gave the quiz questions");
}
@Override
public void speech() {
System.out.println(this.name+" ready the speech");
}
}
public interface YearlySports extends Sports {
void playCricket();
void playFootball();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment