面向對象的例子


package com.example.demo;

//這是一個簡單的面向對象的例子,抽象具體事物變成模型
public class Person {
    //對象定義:對現實中具體事物(萬事萬物)的抽象

    //對人進行抽象,應該有的屬性,嘴,腳
    //嘴有吃這個功能,腳有走這個功能

    //屬性:嘴
    private String mouth;
    private String foot;

    //他們的方法
    //嘴的吃
    public void eat(){
        System.out.println("mouth can eat");
    }

    //腳的走
    public void run(){
        System.out.println("foot can run");
    }

    public Person(){

    }

    public static void main(String[] args) {
        //創建對象
        Person person  = new Person();
        //調用人這個對象所擁有的功能
        person.eat();
        person.run();

    }
}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM