Showing posts with label OOP. Show all posts
Showing posts with label OOP. Show all posts

Wednesday, January 4, 2012

JAVA : OOP - Interface

Below example for Interface programming.


interface calc {
public int calc(int a, int b);
}
public class MyInterface implements calc{
public int calc(int a,int b )
{
return a + b; }
public static void main(String[] args)
{
MyInterface testInterface = new MyInterface();
int total;
total = testInterface.calc(1,7);
System.out.println("Total:" + total);
}
}


Interface only declare the method only. not include with the method body.

Java : OOP - Pass object to Method

Example for Pass object to Method.


class Kira {
void print(String str) {
System.out.println("In Kira :" + str);
}
}
public class test {
public static void main(String[] args) {
//System.out.println("testing 1 2 3....");
Kira kira = new Kira();
kira.print("Testing Kira");
}
}


Save file as test.java. Compile and run.....