RSS2.0

Looking Something??



[Java] Simple Java Coding - Hello World!

Monday, March 3, 2008

Simple Java Coding – Hello World!

What’s wrong with the program below?

public class Main

{

void show(){

System.out.println("Hello World!");

}

public static void main (String args[])

{

int value;

show();

System.out.println(value);

}

};

The answer :

  1. the value of variable int value isn’t initialized yet
  2. Method which has static access modifier can only call method which type is static

Correction :

public class Main

{

static void show(){

System.out.println("Hello World!");

}

public static void main (String args[])

{

int value = 0;

show();

System.out.println(value);

}

};

This program will run well. Try it to make a simple java program.


0 comments: