Advertisement
Swampert420

Untitled

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