什麽是面向對象程序設計?人類和人類對象的使用
阿新 • • 發佈:2017-10-23
pan int ati ogr static min pre pack span
什麽是面向對象程序設計?
我們稱為OOP(Object Oriented Programming)
就是非結構化的程序設計
要使用類和對象的方法來進行編程
什麽是類,什麽是對象
類就是封裝了屬性和行為的小程序,能夠實現特定的功能。行為就是指方法,就是函數。什麽是屬性,就是自定義的字段,也稱為變量。
什麽對象?
對象就是類的實例。
package com.swift; public class Person { public int id; public String name; public int age; public String city;public String introduce() { return "My id=" + id + ", name=" + name + ", age=" + age + ", city=" + city ; } }
package com.swift; public class DemoPerson { public static void main(String[] args) { // TODO Auto-generated method stub Person p1=new Person(); Person p2=new Person(); Person p3=new Person(); Person p4=new Person(); p1.id=110001; p1.name="劉備"; p1.age=43; p1.city="蜀國"; p2.id=110002; p2.name="關羽"; p2.age=35; p2.city="蜀國"; p3.id=110003; p3.name="張飛"; p3.age=32; p3.city="蜀國"; p4.id=110004; p4.name="諸葛亮"; p4.age=25; p4.city="蜀國"; System.out.println(p1.introduce()); System.out.println(p2.introduce()); System.out.println(p3.introduce()); System.out.println(p4.introduce()); } }
什麽是面向對象程序設計?人類和人類對象的使用