您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 第二章 Java面向对象编程
JavaOOP ofJava LanguageClick to buy NOW!PDFXCHANGEtrack.comClick to buy NOW!PDFXCHANGEtrack.comSoftware Engineering School of CQU. Copyright 2008.Software Engineering School of CQU. Copyright 2008.��privatepublic�����thissuperClick to buy NOW!PDFXCHANGEtrack.comClick to buy NOW!PDFXCHANGEtrack.comSoftware Engineering School of CQU. Copyright 2008.Software Engineering School of CQU. Copyright 2008.11�OO(Everything isobject!)––(Type)A class is a blueprint or prototype from which objects arecreated.–An object is a software bundle of related state andbehavior.Click to buy NOW!PDFXCHANGEtrack.comClick to buy NOW!PDFXCHANGEtrack.comSoftware Engineering School of CQU. Copyright 2008.Software Engineering School of CQU. Copyright 2008.11�OOP–Packaging/Encapsulated–Polymorphism–InheritanceJavaC++Java C++OO“.”“”“import”“include”InterfaceClick to buy NOW!PDFXCHANGEtrack.comClick to buy NOW!PDFXCHANGEtrack.comSoftware Engineering School of CQU. Copyright 2008.Software Engineering School of CQU. Copyright 2008.2 class2 class�Java[modifiers]classname { }class EmpInfo{String name;String designation;String department;void print() {System.out.println(name+ is + designation + at + department);}}[modifiers]publicdefaultnameJavaClick to buy NOW!PDFXCHANGEtrack.comClick to buy NOW!PDFXCHANGEtrack.comSoftware Engineering School of CQU. Copyright 2008.Software Engineering School of CQU. Copyright 2008.2 class2 class�EmpInfoemployee = new EmpInfo(); // creates instanceemployee.name= Robert Javaman ; // initializesemployee.designation= Manager ; // the threeemployee.department= Coffee Shop ; // membersemployee.print();// prints the detailsClick to buy NOW!PDFXCHANGEtrack.comClick to buy NOW!PDFXCHANGEtrack.comSoftware Engineering School of CQU. Copyright 2008.Software Engineering School of CQU. Copyright 2008.2 class2 class�privateprotectedpublicClick to buy NOW!PDFXCHANGEtrack.comClick to buy NOW!PDFXCHANGEtrack.comSoftware Engineering School of CQU. Copyright 2008.Software Engineering School of CQU. Copyright 2008.2 class2 class�[modifiers]return_type name ([argument_list])block [throws exception] {block}[modifiers],publicdefaultprotectedprivatereturn_typeprimitive type or referenced type.void()nameJava[argument_list],public class MyDate{private intday, month, year;public void addDay(intd, intm, inty){day = day+ d;month += m;year += y;}}Click to buy NOW!PDFXCHANGEtrack.comClick to buy NOW!PDFXCHANGEtrack.comSoftware Engineering School of CQU. Copyright 2008.Software Engineering School of CQU. Copyright 2008.2 class2 class�thispublic class MyDate{private intday, month, year;public Mydate(intday, intmonth, intyear) {this.day=day;this.month=month;this.year=year;}public void tomorrow() {this.day= this.day+ 1;}}thisthis.daydayClick to buy NOW!PDFXCHANGEtrack.comClick to buy NOW!PDFXCHANGEtrack.comSoftware Engineering School of CQU. Copyright 2008.Software Engineering School of CQU. Copyright 2008.2 class2 class�Constructor–––class EmpInfo{String name;String destination;String department;EmpInfo(Stringname, String designation , String department) {this.name= name;this.designation= designation ;this.department= department;}void print() {System.out.println(name+ is + designation + at + department);}}Click to buy NOW!PDFXCHANGEtrack.comClick to buy NOW!PDFXCHANGEtrack.comSoftware Engineering School of CQU. Copyright 2008.Software Engineering School of CQU. Copyright 2008.2 class2 class�–—class Point {public double x; /*instance variable*/public double y; /*instance variable*/Point() { /*constructor to initialize to default zero value*/x = 0.0;y = 0.0;}/*constructor to initialize to specific value*/Point(doublex, double y) {this.x= x; /*set instance variables to passed parameters*/this.y= y;}}Click to buy NOW!PDFXCHANGEtrack.comClick to buy NOW!PDFXCHANGEtrack.comSoftware Engineering School of CQU. Copyright 2008.Software Engineering School of CQU. Copyright 2008.2 class2 class�–class Point {public double x; /*instance variable*/public double y; /*instance variable*/Point() { /*constructor to initialize to default zero value*/x = 0.0;y = 0.0;}/*constructor to initialize to specific value*/Point(doublex, double y) {this.x= x; /*set instance variables to passed parameters*/this.y= y;}Point(doublex) {this(x,0);}Click to buy NOW!PDFXCHANGEtrack.comClick to buy NOW!PDFXCHANGEtrack.comSoftware Engineering School of CQU. Copyright 2008.Software Engineering School of CQU. Copyright 2008.2 class2 class�–Java��Click to buy NOW!PDFXCHANGEtrack.comClick to buy NOW!PDFXCHANGEtrack.comSoftware Engineering School of CQU. Copyright 2008.Software Engineering School of CQU. Copyright 2008.public
本文标题:第二章 Java面向对象编程
链接地址:https://www.777doc.com/doc-4377208 .html