笔记1:熊熊熊猫开始敲代码啦

已是大四狗,,   才开始学习不晚吧,   求大神支支招怎么高效学习啊  学习步骤 要看什么书 做什么项目之类的

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");
	}
}
   记录一下,   原因什么的我也不清楚。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值