[今天学习了 创建类和方法 实现将冰箱打开 把胖虎放进去 把冰箱焊死]
1 package demobag; 2 3 public class Demo1 { 4 5 public static void main(String[] args) { 6 // TODO Auto-generated method stub 7 Fridge f1 = new Fridge(); 8 f1.open(); 9 Animal fatTiger = new Animal(); 10 fatTiger.go(); 11 Fridge.close(); 12 } 13 14 }
package demobag; public class Animal { double size=1000; public static void go(){ System.out.println("胖虎进冰箱"); } public static void out(){ System.out.println("胖虎出不来"); } }
package demobag; public class Fridge { double size; public static void open(){ System.out.println("冰箱开了"); } public static void close(){ System.out.println("冰箱焊死了"); } }
实现效果