Abhayraj Singh Exp-5 OOPL (1)
Abhayraj Singh Exp-5 OOPL (1)
Experiment No: 5
Title: Use of Interface
COs to be achieved:
CO2: Understand concepts of Object Oriented Programming and basic characteristics of Java.
Code:
1. Write a program to design interface named stack with the following methods
a. push and pop elements from the stack
interface Stack {
void push(int item);
int pop();
boolean isEmpty();
boolean isFull();
}
2. Design class of college which uses two interfaces named student and teacher. Class college
will use methods declared in interface to display student and teacher personal information.
interface Student {
void showStudentInfo();
}
interface Teacher {
void showTeacherInfo();
}
Output:
For Stack Implementation
Stack is empty
Pushed: 10
Pushed: 20
Popped: 20
Popped: 10
Stack is empty
3. What will be function of the following code ? will this code work ? if not, why ?
Conclusion:
Interfaces help achieve abstraction and multiple inheritance in Java.
They define a contract for implementing classes to follow.
The experiment demonstrated the use of interfaces in stack operations and college data
representation.