定义类

1、面向对象编程(oop)内容总结

2、编码实现定义类

package com.hanqi;

public class Shouji 
{
    //属性  成员变量
    
    String Color;
    
    double Chicun;
    
    int  Weight;
    
    //行为  用方法表示
    
    void dadianhua()
    {
        System.out.println("我能打电话");
    }    
    void shangwang()
    {
        System.out.println("我能上网");
    }
    public static void main(String[] args)
    {
        //生成一个手机的实例  金色,5.5英寸,172克
        
        Shouji  iPhone = new Shouji();
        
        iPhone.Color="金色";
        
        iPhone.Chicun=5.5;
        
        iPhone.Weight=172;
        
        System.out.println("苹果 iPhone 6 Plus 颜色"  +iPhone.Color);
        
        System.out.println("苹果 iPhone 6 Plus 尺寸"  +iPhone.Chicun);
        
        System.out.println("苹果 iPhone 6 Plus 重量"  +iPhone.Weight);
        
        iPhone.dadianhua();
        
        iPhone.shangwang();    
    }
}
定义类

原文地址:https://www.cnblogs.com/wangchuanqi/p/5235547.html