I intend to Microsoft-related technologies but in this period, i'm researching Java by comparing it against C# .
Today, I will start out a first example while learning Java.
- IDE: DR.Java - This IDE is the best one for beginners who want to "invade" into Java's world.
- Purporse: Examining and comparing between Java and C# about implementing interface
As shown below, the code has one interface named iHello, one class
named Hello, one class named Example in which has a function named void
main is used as a starting point of the program.
Java Code:
/*
This is a simple Java program.
Call this file "Example.java".
*/
class Example {
// Your program begins with a call to main().
public static void main(String args[]) {
System.out.println("This is a simple Java program.");
Hello myhello=new Hello();
myhello.say(3);
myhello.talk("Hi you");
}
}
interface iHello
{
public void say(int in_x);
public void talk(String tome);
}
class Hello implements iHello
{
int x=100;
String y="hello";
Hello()
{
System.out.println("Y is " + x);
}
public void say(int in_x)
{
System.out.println("Implementing say in iHello in_x: " + in_x);
}
public void talk(String tome)
{
System.out.println("Implementing talk in iHello tome: "+ tome);
}
}
- in C#, I must use the mark : for implementing interface. In Java, I must use the keyword implements
Subscribe to:
Post Comments
(
Atom
)
0 comments:
Post a Comment