其實有關錯誤如下:
HelloWorld.java:11:cannot find symbol
symbol:variable i
location:class HelloWorld
int n=hw.i+hw.j;
^
HelloWorld.java:11:cannot find symbol
symbol:variable j
location:class HelloWorld
int n=hw.i+hw.j;
^
HelloWorld.java:11:imcompatible types
found:java.lang.String
requirt:int
int n=hw.i+hw.j;
^
HelloWorld:java:12:cannot find symbol
symbol:variable c1
location: class HelloWorld
int c=hw.c1+hw.c2
^
HelloWorld.java:cannot find symbol
symbol:variable c2
location:class HelloWorld
int c=hw.c1+hw.c2
^
HelloWorld.java:12:incompatible types
found:java.lang.String
require:int
int c+hw.c1+hw.c2
^
不過如果將有關程式碼改成如下, 反而可以執行到有關程式:
public class HelloWorld
{
public static void main(String args[])
{
int i=33;
int j=44; //定義兩個整型變數
char c1='a';
char c2='b'; //定義兩個字符型變量
HelloWorld hw=new HelloWorld(); // 創建對象,對象引用為hw
int n=i+j; // 將兩個整型變數做加法運算
int c=c1+c2; // 將兩個字符型的變量進行相加
System.out.println(n);
System.out.println(c);
}
}