Class Running Notes 12th Oct
Class Running Notes 12th Oct
*imp
Interfaces in Java:
i
thi
methods,which means Interface cannot hold concrete methods upto Java7)
ipa
faq:
methods.
sh
Structure of abstract methods:
ate
return_type method_name(para_list);
nk
faq:
=>The methods which are declared with method_body are known as Concrete
methods.
//method_body
---------------------------------------------------------------
i
thi
Rule-1 : we use "interface" keyword to declare interfaces.
ipa
syntax:
interface Interface_name
{
Ma
//members
}
sh
automatically "public"
Note:
nk
Note:
(i)Static Variables in interfaces will get the memory within the interface
i
thi
cannot be modified.
ipa
faq:
syntax:
class ImplClass implements Interface
//members
i
thi
methods of Interface.
Note:
ipa
=>We create object for implementation class and the object is known as
"Implementation Object".
Ma
Rule-9 : Interface canbe declared with any number of abstract methods
without restriction.
sh
Rule-10 : Implementation class must construct body for all abstract methods
ate
of Interface.
nk
methods.
Ve
Diagram:
i
thi
ipa
Ex: Ma
ITest.java
package test;
public interface ITest {
int k=30;
sh
void m(int x);
void dis();
}
ate
IClass.java
nk
package test;
public class IClass implements ITest{
public void m(int x)//Implemented and Overriding method
{
Ve
System.out.println("===m(x)====");
System.out.println("The value x:"+x);
}
public void dis()//Implemented and Overriding method
{
System.out.println("====dis()====");
System.out.println("The value k:"+k);
}
public void show(int z)//Non-Implemented method
{
System.out.println("====show(z)====");
System.out.println("The value z:"+z);
}
}
DemoInterface1.java(MainClass)
package maccess;
import test.*;
public class DemoInterface1 {
public static void main(String[] args) {
i
thi
System.out.println("The value k:"+ITest.k);
//ITest.k=300;//Error
//ITest ob = new ITest();//Error
IClass ob = new IClass();//Imple
ipa
ob.m(123);
ob.dis();
ob.show(124);
} Ma
}
o/p:
====dis()====
nk
====show(z)====
Ve
----------------------------------------------------------------------