AIM:
To write a Java program to implement single inheritance using simple methods.
ALGORITHM:
1. Start the program.
2. Declare the base class A.
3. Declare and define the function methodA() that prints message “Base class
method”.
4. Declare the other class B as derived class of base class A.
5. Declare and define the function methodB() that prints “Child class method “.
6. Create the class result derived from student and marks.
7. Declare the derived class object and call the functions .
8. Stop the program
SOURCE CODE:
class A {
public void methodA() {
System.out.println("Base class method");
class B extends A {
public void methodB() {
System.out.println("Child class method");
public static void main(String args[]) {
B obj = new B();
obj.methodA();
obj.methodB();
}
OUTPUT:
RESULT:
Thus the program for single inheritance executed and verified successfully.
AIM:
To write a Java program to implement Student Information system using single
inheritance concept.
ALGORITHM:
1. Start the program.
2. Declare the base class student.
3. Declare and define the function getdata() that gets student information.
4. Declare the other class exam as derived class of base class student.
5. Declare and define the function calculation() & show() to calculate and print the
result respectively.
6. Declare the derived class object and call the functions .
7. Stop the program
SOURCE CODE:
import java.util.Scanner;
class student {
protected int regno, m1, m2, m3, m4, m5;
protected String name, dept;
void getdata() {
Scanner in = new Scanner(System.in);
System.out.println("Enter the Register Number");
regno = in.nextInt();
System.out.println("Enter the Name");
name = in.next();
System.out.println("Enter mark1");
m1 = in.nextInt();
System.out.println("Enter mark2");
m2 = in.nextInt();
System.out.println("Enter mark3");
m3 = in.nextInt();
System.out.println("Enter mark4");
m4 = in.nextInt();
System.out.println("Enter mark5");
m5 = in.nextInt();
class exam extends student {
private int total;
private String result;
private float average;
void calculation() {
total = m1 + m2 + m3 + m4 + m5;
average = total / 5;
if (m1 >= 50 && m2 >= 50 && m3 >= 50 && m4 >= 50 && m5 >= 50) {
result = "PASS";
} else {
result = "FAIL";
void show() {
System.out.println("\t\t\tStudent Details");
System.out.println("Name = " + name);
System.out.println("Register Number = " + regno);
System.out.println("Marks of 1st Subject = " + m1);
System.out.println("Marks of 2nd Subject = " + m2);
System.out.println("Marks of 3rd Subject = " + m3);
System.out.println("Marks of 4th Subject = " + m4);
System.out.println("Marks of 5th Subject = " + m5);
System.out.println("Total Marks = " + total);
System.out.println("Result = " + result);
System.out.println("Percentage = " + average + "%");
}
class J3bInheritance {
public static void main(String[] args) {
exam ex = new exam();
System.out.println("STUDENT INFORMATION");
ex.getdata();
ex.calculation();
ex.show();
}
OUTPUT:
RESULT:
Thus the program for Student Information System using single inheritance executed and
verified successfully.
AIM:
To write a Java program to implement Hierarchical inheritance.
ALGORITHM:
1. Start the program.
2. Declare the base class class A with methodA() that prints “method of Class A”.
3. Declare the derived class class B that extends from class A with methodB() that
prints “method of Class B”.
4. Declare the derived class class C that extends from class A with methodC() that
prints “method of Class C”.
5. Declare the derived class class D that extends from class A with methodD() that
prints “method of Class D”.
6. Declare a main class MyClass and create objects for class B, C, and D.
7. Using those objects, call the respective methods.
8. Stop the program.
SOURCE CODE:
class A {
public void methodA() {
System.out.println("Method of Class A");
class B extends A {
public void methodB() {
System.out.println("Method of Class B");
class C extends A {
public void methodC() {
System.out.println("Method of Class C");
class D extends A {
public void methodD() {
System.out.println("Method of Class D");
public class MyClass {
public static void main(String args[]) {
B obj1 = new B();
C obj2 = new C();
D obj3 = new D();
obj1.methodA();
obj2.methodA();
obj3.methodA();
obj1.methodB();
obj2.methodC();
obj3.methodD();
}
OUTPUT:
RESULT:
Thus the program for hierarchical inheritance executed and verified successfully.
AIM:
To write a Java program to design and implement RMI (Remote Method Invocation).
ALGORITHM:
1. Create an interface named FactInterface.
2. Declare the fact() method in the FactInterface.
3. Create FactImplementation class by implementing FactInterface and define the fact()
method.
4. Create RmiServer class and create an object for FactImplementation.
5. Bind that object to the RMI registry using Naming.rebind() and display "Server
ready".
6. Create RmiClient class and look up the object in the server’s registry using
Naming.lookup().
7. Get the object from the server and typecast it as a reference.
8. Using that object, invoke the fact() method and display the output.
9. Stop the program.
SOURCE CODE:
import java.rmi.*;
public interface FactInterface extends Remote {
public int fact(int n) throws RemoteException;
import java.rmi.server.*;
class FactImplementation extends UnicastRemoteObject implements FactInterface {
public FactImplementation() {
super();
public int fact(int n) {
int f = 1;
for (int i = 1; i <= n; i++) {
f = f * i;
return f;
import java.rmi.*;
import java.net.*;
class RmiServer {
public static void main(String args[]) {
FactImplementation fi = new FactImplementation();
try {
Naming.rebind("rmi://localhost/Server", fi);
System.out.println("Server ready");
} catch (Exception e) {
System.out.println(e);
import java.rmi.*;
import java.io.*;
class RmiClient {
public static void main(String args[]) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
System.out.println("Enter the server name or IP address:");
String url = br.readLine();
String host = "rmi://" + url + "/Server";
FactInterface serv = (FactInterface) Naming.lookup(host);
System.out.println("Enter a number:");
int n = Integer.parseInt(br.readLine());
int fact = serv.fact(n);
System.out.println("Factorial of " + n + " is " + fact);
} catch (Exception e) {
System.out.println(e);
}
}
OUTPUT:
RESULT:
Thus the RMI using factorial method program executed and verified successfully.