In: Computer Science
Define a class named University with data members such as
campus_name,
courses_offered and no_of_faculty. Include appropriate methods and
illustrate
the following object oriented concepts.
i.
Polymorphism.
ii.
Static methods
Code in java
//creating university class
class University{
//initializing the attributes
String campus_name="null";
String course_offered="null";
int no_faculty=20;
//function used to check eligibility
public void checkeligibility(int no){
//function take one input from user which is number of
faculty(no)
//checking if the university has minimum faculty number
if(no>=no_faculty)
//if not println
System.out.println("Eligible");
else
//else println
System.out.println("Not Eligible");
}
}
//creating another class which inherit the university class
class college extends University{
//initializing the static variable which can be accessd without
creating a instance
static int seatcount=300;
//this method represent Polymorphism(Polymorphism uses methods from
parent class to perform different tasks)
public void checkeligibility(int no){
//checking if the college has minimum faculty number
if(no==no_faculty)
//if not println
System.out.println("This college is Eligible");
else
//else println
System.out.println("This college is Not Eligible");
}
//this is an static method which can be accessed without creating
the instance
static void seatsavailable(){
//function will print the seat count
System.out.println("seats availabale:-"+seatcount);
}
}
//main class
class Main{
public static void main(String[] args){
//creating instance of university class
University u1=new University();
//calling the function
u1.checkeligibility(22);
//creating instance of college class
college c1=new college();
//calling the method(Polymorphism)
c1.checkeligibility(22);
//calling the static method without creating the insatnce
college.seatsavailable();
}
}
Screenshots
Input\output