Advertisement
Swampert420

Untitled

Aug 6th, 2022
744
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package Interface;
  2.  
  3. interface StudentDetails {
  4.  
  5.     public void setId(int id);
  6.  
  7.     public int getId();
  8.    
  9.     default void print(String name){
  10.         System.out.println(name);
  11.     }
  12. }
  13.  
  14. interface TeacherDetails {
  15.  
  16.     public void setId(int id);
  17.  
  18.     public int getId();
  19. }
  20.  
  21. class Subject implements StudentDetails, TeacherDetails {
  22.  
  23.     int id;
  24.     String subject;
  25.  
  26.     public void setSubject(String subject) {
  27.         this.subject = subject;
  28.     }
  29.  
  30.     public String getSubject() {
  31.         return subject;
  32.     }
  33.  
  34.     @Override
  35.     public void setId(int id) {
  36.         this.id = id;
  37.     }
  38.  
  39.     public int getId() {
  40.         return id;
  41.     }
  42.    
  43.     @Override
  44.     default void display(String name){
  45.         System.out.println("Lmao"+name);
  46.     }
  47. }
  48.  
  49. public class MultipleInheritanceUsingClass {
  50.  
  51.     public static void main(String[] args) {
  52.         Subject subject = new Subject();
  53.         subject.setId(10);
  54.         subject.setSubject("Maths");
  55.         subject.print("Brother");
  56.         System.out.println(subject.getId()+" "+subject.getSubject());
  57.     }
  58.  
  59. }
  60.  
  61. // WAP to inherit the default method of interface
  62.  
Advertisement
RAW Paste Data Copied
Advertisement