import java.io.*;
interface rectangle
{
public int cal(int a, int b);
}
class area implements rectangle
{
public int cal(int a, int b)
{
return(a*b);
}
}
class simple_interface
{
public static void main(String args[])
{
try
{
int x,y;
DataInputStream cin=new DataInputStream(System.in);
System.out.println("Enter length and breath");
x=Integer.parseInt(cin.readLine());
y=Integer.parseInt(cin.readLine());
area a=new area();
System.out.println("The area of rectangle"+a.cal(x,y));
}
catch(Exception e)
{
}
}
}
Embedding the definition of "check.message()" within the creation of the object was a poor way to illustrate how to create an interface. This is a sloppy way of programming that results in ugly, unreadable code and is a practice that should be discouraged (at least for professional applications).
Hi i have confusion in above example is that in java we cant make object or instance of an interface
but you created object of interface check ,i think that is not possible.
Hello sir,
my question is that why have you not mentioned keyword "implements check" after "public class Interface"?
Please reply at mittulmadaan@gmail.com
interface check {
public void message();
}
public class Interface {
public static void main(String[] args) {
try {
check t = new check() {
public void message() {
System.out.println("Method defined in the interface");
}
};
t.message();
} catch (Exception ex) {
System.out.println("" + ex.getMessage());
}
}
}
Output of the program
Method defined in the interface
Download source code
Related Tags for Example to create Interface in java:
c, interface, method, int, group, define, empty, e, im, ce, in, body, as, m, nt, ace, em, me, pty, defined, s, at, is, ha, mpl, s, s, th, hat, face, fin, ple, pl, o
«Previous Index
nonePulkit September 20, 2011 at 12:40 AM
this site is awesome, very useful to me
simple Interface fot Calculate Area of RectangleAnant Mahale February 20, 2012 at 9:17 AM
import java.io.*; interface rectangle { public int cal(int a, int b); } class area implements rectangle { public int cal(int a, int b) { return(a*b); } } class simple_interface { public static void main(String args[]) { try { int x,y; DataInputStream cin=new DataInputStream(System.in); System.out.println("Enter length and breath"); x=Integer.parseInt(cin.readLine()); y=Integer.parseInt(cin.readLine()); area a=new area(); System.out.println("The area of rectangle"+a.cal(x,y)); } catch(Exception e) { } } }
interfaceprashant November 30, 2011 at 1:54 PM
For practice
Interface: error in above programabhishek January 23, 2012 at 4:39 PM
Interface can not be instantiate.
interfacebabita February 14, 2012 at 5:22 PM
how to create java based interface for healthcare and how to connect it to oracle10g
about interfacejohn February 17, 2012 at 7:41 PM
what are the uses of interface
How can i create a web page using java languagejoseph March 5, 2012 at 7:00 PM
please help me out
Not a very good exampleSteve March 21, 2012 at 1:22 AM
Embedding the definition of "check.message()" within the creation of the object was a poor way to illustrate how to create an interface. This is a sloppy way of programming that results in ugly, unreadable code and is a practice that should be discouraged (at least for professional applications).
java codingjaslin May 8, 2012 at 8:54 PM
i have a problem in doing a java code for interface that have button which are need to link with others class.can i have the example?
java-interfacenaren June 18, 2012 at 1:21 PM
Hi i have confusion in above example is that in java we cant make object or instance of an interface but you created object of interface check ,i think that is not possible.
keyword missingMittul Madaan June 30, 2012 at 2:23 PM
Hello sir, my question is that why have you not mentioned keyword "implements check" after "public class Interface"? Please reply at mittulmadaan@gmail.com
haisavari July 11, 2012 at 2:09 PM
interface check { public void message(); } public class Interface { public static void main(String[] args) { try { check t = new check() { public void message() { System.out.println("Method defined in the interface"); } }; t.message(); } catch (Exception ex) { System.out.println("" + ex.getMessage()); } } } Output of the program Method defined in the interface Download source code Related Tags for Example to create Interface in java: c, interface, method, int, group, define, empty, e, im, ce, in, body, as, m, nt, ace, em, me, pty, defined, s, at, is, ha, mpl, s, s, th, hat, face, fin, ple, pl, o «Previous Index
java all programsusila josephine B August 8, 2012 at 7:57 PM
use full
packageDhanz.p August 17, 2012 at 10:51 AM
i won't say about package, i need clear definitions of package..wish u all success.....
how we use bufferReader in javapardeep kaur October 29, 2012 at 4:44 PM
ur all programs are excellent and help me alot....
creating the interractive interfaceshaaban December 30, 2012 at 12:45 PM
dear experts I am a beginner and upcoming programmer, thus I want to know well how to create good interfaces
No interface ImplementationIrfan November 24, 2012 at 4:41 AM
Where is the keywork implements in the class implementing the interface?
Post your Comment