Java Laboratory Record
EXP NO: 04-A - IMPLEMENT SINGLE INHERITANCE AND DEMONSTRATE
USE OF METHOD OVERRIDING
AIM:
To implement single inheritance and to demonstrate use of method overriding.
SOFTWARE REQUIRED:
- A PC with Windows
- JDK 1.6
ALGORITHM:
1. Create a class named 'student' with a method 'detalis' that prints 'psg polytechnic
college'.
2. Create a class named 'deparment' that extends the 'student' class.
3. Override the 'detalis' method in the 'deparment' class to print 'computer networking'.
4. In the 'Exp4a' class's main method: Create objects: 'student', 'deparment', 'student1'.
Call the 'detalis' method on each object.
5. End of the program.
PROGRAM:
class student {
public void detalis() {
[Link]("psg polytechnic college");
}}
class deparment extends student {
@Override
public void detalis() {
[Link]("computer networking");
}}
public class Exp4a {
public static void main(String[] args) {
student student = new student();
[Link]();
deparment deparment = new deparment();
[Link]();
student student1 = new deparment();
[Link]();
}
}
RESULT:
Thus, we have successfully implemented single inheritance and demonstrated the use of
method overriding.