zoukankan      html  css  js  c++  java
  • 手机类练习

    /*定义一个类,用来模拟“手机”事物
    成员变量(属性)
    String brand;//品牌
    double price;//价格
    String color;//颜色
    成员方法(行为)
    public void call(String who){}//打电话
    public void sendMessage(){}//群发短信
    */
    public class Phone{
        //成员变量
        String brand;//品牌
        double price;//价格
        String color;//颜色
        
        //成员方法(行为)
        public void call(String who){
            System.out.println("给"+who+"打电话");
        }
        public void sendMessage(){
            System.out.println("群发短信");
        }
    }

    public class Demo01PhoneOne{
        public static void main(String[] args){
            //根据Phone类,创建一个名为one的对象
            //格式:类名称 对象名=new 类名称();
            Phone one=new Phone();
            System.out.println(one.brand);//null
            System.out.println(one.price);//0.0
            System.out.println(one.color);//null
            System.out.println("=============");
            
            one.brand="苹果";
            one.price=8388.0;
            one.color="黑色";
            System.out.println(one.brand);//苹果
            System.out.println(one.price);//8388.0
            System.out.println(one.color);//黑色
            System.out.println("=============");
            
            one.call("乔布斯");
            one.sendMessage();    
        }
    }


  • 相关阅读:
    协议
    创建属性、属性标签、对象序列化
    JS中generater和箭头函数
    前端forEach在Array、map、set中的使用,weakset,weakmap
    更新最大内码,金蝶开发
    ERP,还需要WEB开发吗
    可读性太低的SQL语句
    事务,视图和索引
    简单子查询
    创建表并添加约束
  • 原文地址:https://www.cnblogs.com/wang1212-/p/10523661.html
Copyright © 2011-2022 走看看