Class Running Notes 13th Oct
Class Running Notes 13th Oct
faq:
(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-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
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)====
===ITest2 m2(y)====
sh
The value y:12
ate
---------------------------------------------------------------
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
}
}
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.*;
i
thi
Scanner s = new Scanner(System.in);
ipa
int x = 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
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: