Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Implementing Java Interface Example

Program :To demonstrate the concept of Interface (multiple inheritance).

Algorithm

Step 1: Start
Step 2: create interface exam with method pass(int)
Step 3: create interface classify with method division(int)
Step 4: create class result that implements exam and classify
Step 5: result r=new result()
Step 6: Read b
Step 7: boolean f=r.pass(b)
Step 8: Read c
Step 9: String str=r.division(c)
Step 10: if(f) go to 11 else to 12
Step 11: print “you have passéd the exam in”,str,”class”
Step 12: print “you are failed”,str
Step 13: stop

Function boolean pass(int mark)

Step 1: Start
Step 2: print mark
Step 3: if(mark>=50)go to 4 else to 5
Step 4: return true go to 6
Step 5: return false
Step 6: exit

Function String division(int avg)

Step 1: Start
Step 2: print avg
Step 3: if(avg>=60) go to 4 else to 5
Step 4: return “FIRST” go to 8
Step 5: if(avg>=50 ) and (avgProgram

import java.io.*;

interface Exam
{
	boolean Pass(int mark);
}

interface Classify
{
	String Division(int avg);
}

class Result implements Exam,Classify
{
	public boolean Pass(int mark)
	{
			if(mark>=50)
				return true;
			else
				return false;
	}

	public String Division(int avg)
	{
		if(avg>=60)
			return "First";
		else if(avg>=50)
			return "Second";
		else
			return "No-Division";
	}	
}

public class MyResult {
	public static void main(String[] args) {
		boolean pass;
		int mark,avg;
		String division;
		DataInputStream in=new DataInputStream(System.in);
		Result res=new Result();
		try
		{
			System.out.println("Enter the mark : ");
			mark=Integer.parseInt(in.readLine());
			System.out.println("Enter the average : ");
			avg=Integer.parseInt(in.readLine());
			pass=res.Pass(mark);
			division=res.Division(avg);
			if(pass)
				System.out.println("Passed - "+ division + ".");
			else
				System.out.println("Failed - " + division+ ".");
		}
		catch(Exception e)
		{
			System.out.println("Error : " + e);
		}
	}
}
Output

Enter the mark :
50
Enter the average :
50
Passed – Second.

Enter the mark :
40
Enter the average :
40
Failed – No-Division.

Implementing Java Interface Example is a post from ShoutToWorld - Let's Learn Let's Shout - Helping bloggers and developers.



This post first appeared on ShoutToWorld, please read the originial post: here

Share the post

Implementing Java Interface Example

×

Subscribe to Shouttoworld

Get updates delivered right to your inbox!

Thank you for your subscription

×