please i need add interface to my code please // Java Program interface University { public void add(int id, String name); } class Person { String name; int id; Person(String name, int id) { this.name = name; this.id = id; } } class Student extends Person { String Specialization; double gpa; Student(String name, int id, String Specialization, double gpa) { super(name, id); this.Specialization = Specialization; this.gpa = gpa; } } class Employee extends Person { String jop; int salary; Employee(String name, int id, String jop, int salary) { super(name, id); this.jop = jop; this.salary = salary; } } public class Main { public static void main(String[] args) { // creating the Objects of sub classes Student s = new Student("Ritika", 20, "CSE", 7.5); Employee e = new Employee("Ajay", 15, "IT", 30000); // creating the Objects of interface University u = new Main(); // calling the methods of sub classes u.add(s.id, s.name); u.add(e.id, e.name); } // Implementation of interface method public void add(int id, String name) { System.out.println("ID: " + id + " Name: " + name); } }
please i need add interface to my code please
// Java Program
interface University {
public void add(int id, String name);
}
class Person {
String name;
int id;
Person(String name, int id) {
this.name = name;
this.id = id;
}
}
class Student extends Person {
String Specialization;
double gpa;
Student(String name, int id, String Specialization,
double gpa)
{
super(name, id);
this.Specialization = Specialization;
this.gpa = gpa;
}
}
class Employee extends Person {
String jop;
int salary;
Employee(String name, int id, String jop,
int salary)
{
super(name, id);
this.jop = jop;
this.salary = salary;
}
}
public class Main {
public static void main(String[] args)
{
// creating the Objects of sub classes
Student s = new Student("Ritika", 20, "CSE", 7.5);
Employee e = new Employee("Ajay", 15, "IT", 30000);
// creating the Objects of interface
University u = new Main();
// calling the methods of sub classes
u.add(s.id, s.name);
u.add(e.id, e.name);
}
// Implementation of interface method
public void add(int id, String name)
{
System.out.println("ID: " + id + " Name: " + name);
}
}
Step by step
Solved in 3 steps with 3 images