java听课记录(java听课记录).doc_第1页
java听课记录(java听课记录).doc_第2页
java听课记录(java听课记录).doc_第3页
java听课记录(java听课记录).doc_第4页
java听课记录(java听课记录).doc_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

java听课记录(java听课记录) java听课记录(java听课记录)object类中定义有public stringtostring()方法,返回值是string类型,描述当前对象的有关信息.在进行string与其他类型数据的连接操作时(如system.out.println(info+person),将自动调用该对象类tostring()方法注:一个字符串和另外一种类型连接时,另外一种类型直接转成string类型,适用于与基本类型的连接.可以根据需要在用户自定义类型中重写tostring()方法object类中定义有:public booleanequals(object obj)方法提供定义对象是否等于的逻辑object的equals(加s是第三人称的意思)方法定义为:x.equals(y),相当于x和y是同一个对象的引用时返回true否则返回false j2sdk提供了一些类,如string,date等,重写了object的equals方法,调用这些类的equals方法,x.equals(y),当x和y所引用的对象是同一类对象且属性内容相等时(不一定是相同的对象),返回true否则返回false可以根据需要在用户定义类型中重写equals方法.对象转型一个父类(也称基类)的引用类型变量可以指向其子类的对象.一个父类的引用不可以访问其子类对象新增的成员(属性和方法)可以使用引用变量instanceof类名来判断该引用型变量所指向的对象是否属于该嘞活该类的子类子类的对象可以当作父类的对象来使用称之为向上转型(u盘casting),反之称之为向下转型(downcasting)注释:父类引用指向子类时,子类自身的属性和方法不可访问如果一定要访问子类属性要进行强制转换思考一下对象转型对可扩展性带来的好处面向对象的核心内容动态绑定和多态动态绑定是指在执行期间(而非编译期)判断所引用对象的实际类型,分局其实际的类型调用其相应的方法将可扩展性达到最好,调用的方法是新new出来的重中之重,要灵活绑定多态存在的必要条件要有继承,要有重写,父类引用指向子类对象用abstract关键字来定义的类叫做抽象类,用bstract定义的方法叫做抽象方法含有抽象方法的类必须被声明为朝向类,抽象类必须被继承,抽象方法必须被重写抽象类不能被实例化抽象方法只需声明不需实现(因为会被子类继承然后子类重写方法)final关键字final的变量的值不能被改变final的成员变量final的局部变量(形参)final的方法不能被重写final的类不能被继承接口多个无关的类可以实现同一个接口一个类可以实现多个无关的接口与继承关系类似,接口与实现类之间存在多态性定义java类的语法格式:-modifierclassextendsimplements interface,interface*)接口的定义接口(interface)是抽象方法和常量值得定义的集合本质上讲,接口是一种特殊的抽象类,这种抽象类中只包含常量和方法的定义,没有变量和方法的实现接口的特点解救可以多重实现接口中声明的属性默认为public staticfinal的,只能是public staticfinal解救中只能定义抽象方法,而且这些方法默认为public的Interfaces caninherit otherinterfaces andadd propertiesand methodsConstruction method:1.The nameof the construction methodmust bethe same as the class name,and thecase must be exactly the same2,the construction method can be modifiedusing fourpermissions modifiers3.The construction method does not havea returnvalue type4,the construction method ofa classcan havemore thanone,mainly byparameter difference5.The methodbody of the construction method canwrite anystatement thatconforms tothe Javasyntax,but mostof the construction methodsare usedto initializedata membersIn Java,the construction method,there is a problemwe need to payspecial attentionto,is thedefault constructor,if atype declarationdoes notshow theconstruction method,then therewill bea defaultmethod,this methodhas noparameters,the methodbody alsois empty,Such aspublic,Customer()However,as longas the class showsthe declaredconstruction method,theconstructionmethod of the lunchdoes notdefault;if youneedtouse it,you mustalso declarethe declarationThe constructionmethod isa specialmethod,different from the general method:1.The nameof theconstructionmethodmustbeexactlythe same astheclassname thatdefines it.There is no return type,not eventhe void2.The invocationof theconstructionmethodis doneusing thenew operationwhen creatingan object,and theconstructionmethodis alsothe object of initialization3.can notbe modifiedby static,final,synchronized,abstract andnative.The constructionmethod cannotinherit fromthe quiltclass Construction methods canbe overloaded.Construction methodwithout parameterscalled thedefault constructor,and thegeneralmethodof constructingmethod cancarry outany activity,but oftenit isdesigned asa varietyof activitiessuch asinitialization,initialize theobject attribute.In Java,must firstset theinitial valueof anyvariable beforeit isused,Java providesa membervariable aninitial valueof tastebud dedicatedto function:constructionmethodconstructionmethod(constructor)isakind ofspecial membermethod,her specialreflected in the followingaspects:1.The constructionmethod nameis thesameastheclassname2,theconstructionmethod doesnot returnany value,and thereisnoreturntype3,each classcan haveanother livemultiple constructionmethods4.Construction methodsare automaticallyexecuted whenobjects arecreated andcan notbe explicitlycalled directlyCommon classString classThe java.lang.String classrepresents immutablecharacter sequencesXxxxxis anobjectofthis classThe monmethods toconstruct String:String(String original):creates acopy of the String object forOriginal String(charvalut):creates a Stringobjectwith acharacter numberString( count):aStringobject iscreated with the countsequence ofcharacters startingwiththeoffset itemwith anarray ofcharacters Stringclass monlyused methods:Public charcharAt(int index)Returns thefirst indexcharacter inthe string Public,int,length()Returns thelength of the string Public,int,indexof(String,STR,int,fromIndex)Returns thefirst positionof theStr inthe string that appearsfromthebeginning ofthe fromIndexPublic,Boolean,equals,IgnoreCase(String,another)Returns thesame stringas another(ignore case)Public,String,replace(char,oldChar,char,newChar)Replace OldCharcharacters withnewChar charactersin a string PublicBoolean startsWith(String prefix(prefix)Determines whetherthe stringstarts withan prefixstring PublicbooleanendsWith(String suffix(suffix)Determines whetherthe stringhas terminatedat thesuffix string Public,String,toUpperCase()Returns astring formingthe uppercaseofthe stringPublic,String,toLowerCase()Returns astring thatis lowercaseinthestringPublicString substring(int beginIndex)Returns thesubstring frombeginIndex tothe endofthestringPublic,String,substring(int,beginIndex,int,endIndex)Returns thesubstring ofthestringstarting frombeginIndex tothe endoftheendIndex Public,String,trim()Returns thestringthatremoves thebeginning andend spacesofthestring Staticoverloading methodPublic,static,String,valueOf(.)Basic typesof datacanbeconverted intostrings:Such as:Public,static,String,valueOf(double,d)Public,static,String,valueOf(int,I)Method publicStringsplit(String regex)can tellastring,separated bythe specifieddelimiter,to returnthe separatedstring array.StringBuffer classJava.lang.StringBuffer s

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论