Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Interface;
- interface StudentDetails {
- public void setId(int id);
- public int getId();
- default void print(String name){
- System.out.println(name);
- }
- }
- interface TeacherDetails {
- public void setId(int id);
- public int getId();
- }
- class Subject implements StudentDetails, TeacherDetails {
- int id;
- String subject;
- public void setSubject(String subject) {
- this.subject = subject;
- }
- public String getSubject() {
- return subject;
- }
- @Override
- public void setId(int id) {
- this.id = id;
- }
- public int getId() {
- return id;
- }
- @Override
- default void display(String name){
- System.out.println("Lmao"+name);
- }
- }
- public class MultipleInheritanceUsingClass {
- public static void main(String[] args) {
- Subject subject = new Subject();
- subject.setId(10);
- subject.setSubject("Maths");
- subject.print("Brother");
- System.out.println(subject.getId()+" "+subject.getSubject());
- }
- }
- // WAP to inherit the default method of interface
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement