已是大四狗,, 才开始学习不晚吧, 求大神支支招怎么高效学习啊 学习步骤 要看什么书 做什么项目之类的
HelloWorld起步 ,CMD编译运行成功。
继续书上的Hello.java eclipse中运行, 把名字改了下
public class Hello{
public static void main (String args[]){
System.out.println("simple program");
Student stu=new Student();
stu.speak("we are student");
}
<pre name="code" class="html">class Student{
public void speak(String s){
System.out.println(s);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
}
但是会提示No enclosing instance of type Hello is accessible. Must qualify the allocation with an enclosing instance of type Hello (e.g. x.new A() where x is an instance of Hello). 至于什么意思 我也不清楚 我想就是说少了什么东西吧, 随后在class student 前加了个static 没错了 成功运行。
之后写书上另一个联合编译程序的时候,无意中想到要是颠倒一下class类的顺序会怎么样(因为以前C语言里面就有一个 如果有其他调用,main在前面的话 需要在main里也写出来 ) 结果根本不需要加static 也可以运行 如下:
class Student{
public void speak(String s){
System.out.println(s);
}
}
public class Hello{
public static void main (String args[]){
System.out.println("simple program");
Student stu=new Student();
stu.speak("we are student");
}
}
记录一下, 原因什么的我也不清楚。。。