0% found this document useful (0 votes)
0 views

Class Running Notes 13th Oct

The document explains the differences between implemented and non-implemented methods in interfaces, detailing that implemented methods have bodies while non-implemented methods do not. It outlines rules regarding interfaces, such as the inability to declare blocks and constructors, and the ability to extend other interfaces. Additionally, it provides examples of interface implementation in Java, demonstrating how multiple classes can implement the same interface without restriction.

Uploaded by

kg666235
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Class Running Notes 13th Oct

The document explains the differences between implemented and non-implemented methods in interfaces, detailing that implemented methods have bodies while non-implemented methods do not. It outlines rules regarding interfaces, such as the inability to declare blocks and constructors, and the ability to extend other interfaces. Additionally, it provides examples of interface implementation in Java, demonstrating how multiple classes can implement the same interface without restriction.

Uploaded by

kg666235
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Dt : 13/10/2022

faq:

what is the diff b/w

(i)Implemented methods

(ii)Non-Implemented methods

i
thi
(i)Implemented methods:

=>The methods which are taken from interfaces and constructed with bodies are

ipa
known as Implemented methods.

Ma
(ii)Non-Implemented methods:

=>The methods which are not taken from the interfaces are known as

Non-Implemented methods.
sh
----------------------------------------------------------------------

Rule-12 : Interface cannot be declared with blocks and Constructors


ate

Rule-13 : Interface can use the features of another interface using "extends"
nk

keyword.
Ve

Diagram:
i
thi
ipa
Ex:
Ma
ITest1.java

package test;
public interface ITest1 {
sh
public abstract void m1(int x);
}
ate

ITest2.java

package test;
nk

public interface ITest2 extends ITest1{


public abstract void m2(int y);
}
Ve

IClass.java

package test;
public class IClass implements ITest2{
public void m1(int x) {
System.out.println("===ITest1 m1(x)====");
System.out.println("The value x:"+x);
}
public void m2(int y) {
System.out.println("===ITest2 m2(y)====");
System.out.println("The value y:"+y);
}
}

DemoInterface2.java(MainClass)

package maccess;
import test.*;
public class DemoInterface2 {
public static void main(String[] args) {

i
thi
IClass ob = new IClass();
ob.m1(11);
ob.m2(12);
}

ipa
}

o/p: Ma
===ITest1 m1(x)====

The value x:11

===ITest2 m2(y)====
sh
The value y:12
ate

---------------------------------------------------------------

Rule-14 : Interfaces can be implemented to any number of implementation classes


nk

without restriction.
Ve

Diagram:
i
thi
ipa
Ex:

IComparable.java
Ma
package test;
public interface IComparable {
public abstract int compare(int x,int y);
}
sh
GreaterValue.java

package test;
ate

public class GreaterValue implements IComparable{


public int compare(int x,int y) {
if(x>y) return x;
else return y;
nk

}
}
Ve

SmallerValue.java

package test;
public class SmallerValue implements IComparable{
public int compare(int x,int y) {
if(x<y) return x;
else return y;
}
}
DemoInterrface3.java(MainClass)

package maccess;

import test.*;

import java.util.*;

public class DemoInterface3 {

public static void main(String[] args) {

i
thi
Scanner s = new Scanner(System.in);

System.out.println("Enter the value x:");

ipa
int x = s.nextInt();

System.out.println("Enter the value y:");


Ma
int y = s.nextInt();

System.out.println("====Choice====");

System.out.println("1.GreaterValue\n2.SmallerValue");
sh
System.out.println("Enter the Choice:");

switch(s.nextInt())
ate

case 1:
nk

GreaterValue gv = new GreaterValue();

int r1 = gv.compare(x, y);


Ve

System.out.println("GreaterValue:"+r1);

break;

case 2:

break;

default:
System.out.println("Invalid Choice...");

}//end of switch

s.close();

o/p:

i
thi
Enter the value x:

12

ipa
Enter the value y:

13
Ma
====Choice====

1.GreaterValue

2.SmallerValue
sh
Enter the Choice:

1
ate

GreaterValue:13

====================================================================
nk

Assignment:

Construct IArithmetic application using the following Layout:


Ve
i
thi
ipa
Ma
======================================================================
sh
ate
nk
Ve

You might also like