大学JAVA实用教程--第3章 类和接口.pptxVIP

  • 7
  • 0
  • 约1.84万字
  • 约 94页
  • 2017-04-22 发布于湖北
  • 举报
大学JAVA实用教程--第3章 类和接口

第3章类和接口 ;3.1 类;//程序文件名为SetApple.java public class SetApple { public static void main(String[] args) { apple a = new apple();//创建apple类 a.appleweight = 0.5;//实例变量赋值 System.out.println(苹果的重量为1两); System.out.println(a.bite());//调用实例方法 a.appleweight = 5; System.out.println(苹果的重量为5两); System.out.println(a.bite()); } };//自定义类 class apple { //属性 long applecolor;//对应苹果的颜色 double appleweight;//苹果的重量 boolean eatup;//是否吃完 //类方法 public boolean bite() { if (appleweight1) { System.out.println(苹果已经吃完了!哈哈); eatup = true; }; else { System.out.println(苹果吃不下了!:(); eatup =

文档评论(0)

1亿VIP精品文档

相关文档