Simple Java Coding – Hello World!
What’s wrong with the program below?
public class
{
void show(){
System.out.println("Hello World!");
}
public static void main (String args[])
{
int value;
show();
System.out.println(value);
}
};
The answer :
- the value of variable int value isn’t initialized yet
- Method which has static access modifier can only call method which type is static
Correction :
public class
{
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:
Post a Comment