0% found this document useful (0 votes)
2 views2 pages

Java File

The document presents two Java programs demonstrating the use of interfaces. The first program illustrates shared constants in an interface with a SavingAccount class that utilizes these constants. The second program shows how interfaces can be inherited, with an AllInOne interface that combines functionalities of Printer and Scanner, implemented by a Machine class.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Java File

The document presents two Java programs demonstrating the use of interfaces. The first program illustrates shared constants in an interface with a SavingAccount class that utilizes these constants. The second program shows how interfaces can be inherited, with an AllInOne interface that combines functionalities of Printer and Scanner, implemented by a Machine class.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Practical

WAP to illustrate the use of shared constants in interfaces java

interface Bank{
double minBalance=1000;
double intrestRate = 5;

class SavingAccount implements Bank{

double balance;
String name;

SavingAccount(double balance,String name){


[Link] = balance;
[Link]=name;
}

void display(){
[Link]("Available Balance: "+balance);
[Link]("Available Holder Name: "+name);
[Link]("Minimum Balance: "+minBalance);
[Link]("Intrest Rate: "+intrestRate);

}
}

public class SharedConstant {


public static void main(String[] args){
SavingAccount sc= new SavingAccount(2000,"Khush Chawla");

[Link]();

}
}

OUTPUT
Practical
WAP to show how interfaces can be inherited themselves.

interface Printer {
void print();
}

interface Scanner {
void scan();
}

interface AllInOne extends Printer, Scanner {


void fax();
}

class Machine implements AllInOne {

public void print() {


[Link]("Printing document...");
}

public void scan() {


[Link]("Scanning document...");
}

public void fax() {


[Link]("Sending fax...");
}
}

public class InterfaceInheritance {


public static void main(String[] args) {
Machine m = new Machine();
[Link]();
[Link]();
[Link]();
}
}

OUTPUT

You might also like