面向?qū)ο蟮暮锰幘褪呛唵?你直接調(diào)用方法,完全不需要知道這個(gè)方法的具體實(shí)現(xiàn),
當(dāng)雄網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián),當(dāng)雄網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為當(dāng)雄上千多家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站制作要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的當(dāng)雄做網(wǎng)站的公司定做!
比如:你要吃滿漢全度
面向過程:你要自己學(xué)會(huì)做滿漢全席, ?在代碼體現(xiàn)中就是你要知道這個(gè)方法的實(shí)現(xiàn)過程.
面向?qū)ο?你只要找個(gè)會(huì)做的廚師就行. 在代碼體現(xiàn)中就是你只要知道這個(gè)方法名,不需要知道過程
偽代碼
//類
public?class?student{
//屬性
int?age;
String?name;
int?num;
//構(gòu)造器
student(int?age,String?***){
this.age=age;
****
}
//?重寫toString方法
String?toString(){
}??
//入口方法
main(){
syso(new?Student(25,"小明",10416313).toString);//對(duì)象
}
}
純手打希望采納
1.
public?abstract?class?Worker?{
private?String?name;
public?Worker(){}
public?Worker(String?name){
this.name=name;
}
public??abstract?void?introduce();
public?String?getName()?{
return?name;
}
public?void?setName(String?name)?{
this.name?=?name;
}
}
2.
public?class?Painter?extends?Worker{
public?Painter?(){
super("Jack");
}
@Override
public?void?introduce()?{
System.out.println("我叫"+getName()+",我的工作是刷油漆");
}
}
3.
public?class?Fixex?extends?Worker{
public?Fixex?(){
super("Tom");
}
@Override
public?void?introduce()?{
System.out.println("我叫"+getName()+",我的工作是修汽車");
}
}
4.
public?static?void?main(String[]?args)?{
Worker?fixex?=?new?Fixex();
Worker?painter?=?new?Painter();
fixex.introduce();
painter.introduce();
}
public class Admins implements Userinterface{
private String name;
private String password;
private static int userNum;
public Admins() {
userNum ++;
}
public Admins(String name, String password) {
this.name = name;
this.password = password;
userNum ++;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return this.password;
}
public String toString() {
return "Total: " + Admins.userNum + "\nName: " + this.name + "\nPassword: " + this.password;
}
public static void main(String [] args) {
Userinterface [] users = new Userinterface[]{new Admins("jeryy", "11111"), new Admins("green", "123123")};
for(Userinterface u: users) {
System.out.println(u);
}
}
}
interface Userinterface{
public void setPassword(String password);
public String getPassword();
public String toString();
}
public class Bins{
public static void main(String [] args) {
int len = 10;
int [] dist = new int [len];
for(int i = 0; i dist.length; i ++) {
dist[i] = (int)(Math.random() * 100);
}
java.util.Arrays.sort(dist);
System.out.println("生成數(shù)組如下: ");
for(int i: dist) {
System.out.print(i + "\t");
}
java.util.Scanner san = new java.util.Scanner(System.in);
System.out.print("輸入要查找的數(shù): ");
int key = san.nextInt();
int res = Bins.binSearch(dist, key);
//System.out.println(res);
String info = (res =0 ) ? (key + ":" + res) : "查找失敗";
System.out.println(info);
}
public static int binSearch(int [] dist, int key) {
java.util.Arrays.sort(dist);
return java.util.Arrays.binarySearch(dist, key);
}
}
在其他類中的調(diào)用格式如下:
如果如果變量是static的,也就是靜態(tài)成員變量,調(diào)用的格式是:類名.變量名
如果是非靜態(tài)的,也就是沒有用static修飾的話,調(diào)用的格式是:對(duì)象名.變量名(當(dāng)然,這個(gè)對(duì)象是由對(duì)應(yīng)類產(chǎn)生的)
方法的調(diào)用格式與變量的調(diào)用格式類似 。
在本類中調(diào)用時(shí)直接寫方法名或變量名。
把 人 封裝成一個(gè)類Person,繼承這個(gè)類 變有了 人應(yīng)該有的屬性
把 家庭成員關(guān)系封裝一個(gè)類Family,繼承這個(gè)類有了家庭關(guān)系的屬性
把工作封裝成一個(gè)接口Jop,繼承這個(gè)接口實(shí)現(xiàn)了工作的方法
由于Person 和 Family 屬性都是固定的,即每個(gè)人的情況基本都一樣所以封裝成類
Jop 則是因?yàn)?每個(gè)人的工作不一樣,所有做成接口,究竟是什么樣的工作讓這個(gè)人來實(shí)現(xiàn)
這里Person 和 Family需要的屬性并不多,所以我統(tǒng)一將他們封裝了一個(gè)類 Person 實(shí)現(xiàn)代碼如下:
public?class?XiaoHong?extends?Person?implements?Jop?{
public?XiaoHong(String?name,?String?sex,?String?Father,?String?Mother,
String?Son)?{
super(name,?sex,?Father,?Mother,?Son);
//?TODO?Auto-generated?constructor?stub
}
public?static?void?main(String[]?args)?{
XiaoHong?xiaohong?=?new?XiaoHong("小紅","女","李雷",?"韓梅梅",?"討厭啦!人家還?。?);
System.out.println(xiaohong);
xiaohong.work();
}
@Override
public?void?work()?{
System.out.println("我是一個(gè)高中生");
}
}
/********************************************************************************/
public?class?Person?{
private?String?name?=?"I?Don't?Know";
private?String?sex?=?"I?Don't?Know";
private?String?Father?=?"I?Don't?Know";
private?String?Mother?=?"I?Don't?Know";
private?String?Son?=?"I?Don't?Know";
public?Person(String?name,?String?sex,?String?myFather,?String?myMother,
String?mySon)?{
super();
this.name?=?name;
this.sex?=?sex;
this.Father?=?myFather;
this.Mother?=?myMother;
this.Son?=?mySon;
}
public?String?getName()?{
return?name;
}
public?String?getSex()?{
return?sex;
}
public?String?getMyFather()?{
return?Father;
}
public?String?getMyMother()?{
return?Mother;
}
public?String?getMySon()?{
return?Son;
}
@Override
public?String?toString()?{
return?"Person?[name="?+?name?+?",?sex="?+?sex?+?",?Father="
+?Father?+?",?Mother="?+?Mother?+?",?Son="?+?Son
+?"]";
}
}
/******************************************************************************/
public?interface?Jop?{
public?void?work();
}