- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Lecture 14Introduction to Classes and Objects.ppt
Reference * You have already seen how objects are passed to methods; by passing a reference variable If data changes in an object, you will see the changes from anywhere where you have a reference to the object Reference * public class Child{ private String name; public StringBuilder permanentRecord; public Child(String nameIn){ name = nameIn; permanentRecord = new StringBuilder(); } public void doTask(int taskNum){ switch(taskNum){ case 0: playLoudMusic(); break; case 1: crashCar(); break; case 2: makeMomGrouchy(); break; } } public void playLoudMusic(){ System.out.println(name + s stereo goes boom bam thump bubaa); } public void crashCar(){ System.out.println(name + wrecked the car); } public void makeMomGrouchy(){ System.out.println(name + gave Mom a headache.); } public String toString(){ return name; } public void putDownInPermanentRecord(String offense){ permanentRecord.append(\n + offense); } public String getPermanentRecord(){ return permanentRecord.toString(); } public String getName(){return name;} } Reference * public class Family{ private String name; private Child[] kids; public Family(String nameIn, String[] kidsNames){ name = nameIn; kids = new Child[kidsNames.length]; for(int counter = 0; counter kidsNames.length; counter++) kids[counter] = new Child(kidsNames[counter]); } public void callSchool(){ AssistantPrincipal norm = new AssistantPrincipal(kids); readPermanentRecords(); } public String toString(){ return Welcome to the + name + s house; } public void readPermanentRecords(){ System.out.println(================= Permanent Records ====================); for(Child child: kids) System.out.println(child.getName() + s permanent Record: + child.getPermanentRecord()); } public static void main(String[] args){ String[] kidsNames = {Sue, Bill, Carla, Dan}; Family family = new Family(the Smiths, kidsNames);
您可能关注的文档
- CS510 Concurrent Systems Class 13.ppt
- CS533 Concepts of Operating SystemsClass 14.ppt
- CSE 160 – Lecture 16.ppt
- CSE Annual Research Review and Executive Workshop 2002.ppt
- CSE115ENGR160 Discrete Mathematics031312.ppt
- CTO介入治疗:逆向导丝通过后顺向轨道建立方法.ppt
- CTS Communications ForumCIOsMay 14, 2007.ppt
- Curso de BioestadísticaParte 16Regresión lineal.ppt
- Daniel AmyotQ1817 (URN) Rapporteurdamyot@site.uottawa.ca.ppt
- Data Warehousing资料仓储.ppt
- Lecture 14Introduction to Logistic Regression.ppt
- Lecture 14Mirrors.ppt
- Lecture 14Pervasive Computing Applications.ppt
- Lecture 14Transactions in SQL.ppt
- Lecture 16 Accelerator Design in the XUP Board.ppt
- Lecture 16 Diffraction Chp. 37.ppt
- Lecture 16Interference.ppt
- Lecture 16Object Oriented Modeling Methods.ppt
- Lecture 17 Tues., March 16.ppt
- Lecture 18 Polyelectronic Atoms.ppt
文档评论(0)