一我要做什么
介绍我自己并输出到屏幕
二任务步骤
1定义一个类 属性 姓名, 颜色 ,大小 功能 使用 ,show自己 2创建自己并show1 class BigPineapple{ 2 String name = "菠萝"; 3 String color = "黄色"; 4 String size = "大"; 5 static void use() { 6 System.out.print("给海绵宝宝当房子"); 7 } 8 void show() { 9 System.out.println("名字:"+size+name);10 System.out.println("顔色:"+color);11 System.out.print("作用:");12 use();13 }14 }15 public class Item {16 17 public static void main(String[] args) {18 // TODO Auto-generated method stub19 BigPineapple me = new BigPineapple();20 me.show();21 }22 23 }
名字:大菠萝顔色:黄色作用:给海绵宝宝当房子
*
1错误显示 The public type BigPineapple must be defined in its own file 错误原因 定义了两个public类 解决方法 把不是主函数的类的public去掉2错误显示 Cannot make a static reference to the non-static field color 错误原因 无法在静态方法中引用非静态变量 解决方法 把static void show改为void show*//*遗留问题 1类中函数的public和static什么时候加*/