classes in java

<!-- /* Font Definitions */ @font-face {font-family:Wingdings; panose-1:5 0 0 0 0 0 0 0 0 0; mso-font-charset:2; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:0 268435456 0 0 -2147483648 0;} @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:黑体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimHei; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:1 135135232 16 0 262144 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"/@黑体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:1 135135232 16 0 262144 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} h4 {margin-right:0cm; mso-margin-top-alt:auto; mso-margin-bottom-alt:auto; margin-left:0cm; mso-pagination:widow-orphan; mso-outline-level:4; font-size:12.0pt; font-family:宋体;} h5 {margin-right:0cm; mso-margin-top-alt:auto; mso-margin-bottom-alt:auto; margin-left:0cm; mso-pagination:widow-orphan; mso-outline-level:5; font-size:10.0pt; font-family:宋体;} p.MsoDocumentMap, li.MsoDocumentMap, div.MsoDocumentMap {margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; background:navy; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} tt {mso-ascii-font-family:黑体; mso-fareast-font-family:黑体; mso-hansi-font-family:"Courier New"; mso-bidi-font-family:"Courier New";} p.doclist, li.doclist, div.doclist {mso-style-name:doclist; margin-right:0cm; mso-margin-top-alt:auto; mso-margin-bottom-alt:auto; margin-left:0cm; mso-pagination:widow-orphan; font-size:12.0pt; font-family:宋体; mso-bidi-font-family:"Times New Roman";} span.docemphasis {mso-style-name:docemphasis;} p.doctext, li.doctext, div.doctext {mso-style-name:doctext; margin-right:0cm; mso-margin-top-alt:auto; mso-margin-bottom-alt:auto; margin-left:0cm; mso-pagination:widow-orphan; font-size:12.0pt; font-family:宋体; mso-bidi-font-family:"Times New Roman";} p.docnotetitle, li.docnotetitle, div.docnotetitle {mso-style-name:docnotetitle; margin-right:0cm; mso-margin-top-alt:auto; mso-margin-bottom-alt:auto; margin-left:0cm; mso-pagination:widow-orphan; font-size:12.0pt; font-family:宋体; mso-bidi-font-family:"Times New Roman";} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:595.3pt 841.9pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:42.55pt; mso-footer-margin:49.6pt; mso-paper-source:0; layout-grid:15.6pt;} div.Section1 {page:Section1;} /* List Definitions */ @list l0 {mso-list-id:26876599; mso-list-type:hybrid; mso-list-template-ids:744683172 -1461781090 1359877276 65557586 537320224 -483756230 -2039960242 443444262 -1988839196 2002787194;} @list l0:level1 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:36.0pt; mso-level-number-position:left; text-indent:-18.0pt; mso-ansi-font-size:10.0pt; font-family:Symbol;} @list l1 {mso-list-id:1050886690; mso-list-type:hybrid; mso-list-template-ids:-1731670882 1279394196 -80584096 2106775860 1619722150 393099138 114185658 1212161126 -1080661460 -1262203120;} @list l1:level1 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:36.0pt; mso-level-number-position:left; text-indent:-18.0pt; mso-ansi-font-size:10.0pt; font-family:Symbol;} @list l2 {mso-list-id:1084766004; mso-list-type:hybrid; mso-list-template-ids:-112965140 1613552754 -1424464090 -1283560892 1299193268 -119664116 -750727988 1309448894 -545123464 1572632886;} @list l3 {mso-list-id:1459104210; mso-list-type:hybrid; mso-list-template-ids:506107922 1863337622 1928479148 -837280352 74884130 581724460 559604710 1865338754 1815673754 232056946;} ol {margin-bottom:0cm;} ul {margin-bottom:0cm;} -->

Declaring Classes

1.    Modifiers such as public , private , and a number of others that you will encounter later.

2.    The class name, with the initial letter capitalized by convention.

3.    The name of the class's parent (superclass), if any, preceded by the keyword extends . A class can only extend (subclass) one parent.

4.    A comma-separated list of interfaces implemented by the class, if any, preceded by the keyword implements . A class can implement more than one interface.

5.    The class body, surrounded by braces, { } .

Declaring Member Variables

·         Member variables in a classthese are called fields .

·         Variables in a method or block of codethese are called local variables .

·         Variables in method declarationsthese are called parameters .

Access Modifiers

·         public modifier the field is accessible from all classes.

·         private modifier the field is accessible only within its own class.

Defining Methods

1.    Modifierssuch as public , private , and others you will learn about later.

2.    The return typethe data type of the value returned by the method, or void if the method does not return a value.

3.    The method namethe rules for field names apply to method names as well, but the convention is a little different.

4.    The parameter list in parenthesisa comma-delimited list of input parameters, preceded by their data types, enclosed by parentheses, () . If there are no parameters, you must use empty parentheses.

5.    An exception listto be discussed later.

6.    The method body, enclosed between bracesthe method's code, including the declaration of local variables, goes here.

Overloading Methods

This means that methods within a class can have the same name if they have different parameter lists.

Note

Overloaded methods should be used sparingly, as they can make code much less readable.

Note

Parameters refers to the list of variables in a method declaration. Arguments are the actual values that are passed in when the method is invoked. When you invoke a method, the arguments used must match the declaration's parameters in type and order.

Note

The Java programming language doesn't let you pass methods into methods. But you can pass an object into a method and then invoke the object's methods.

Arbitrary Number of Arguments

You can use a construct called varargs to pass an arbitrary number of values to a method. To use varargs, you follow the type of the last parameter by an ellipsis (three dots, ... ), then a space, and the parameter name. The method can then be invoked with any number of that parameter, including none.

Passing Primitive Data Type Arguments

Primitive arguments, such as an int or a double , are passed into methods by value . This means that any changes to the values of the parameters exist only within the scope of the method. When the method returns, the parameters are gone and any changes to them are lost.

Passing Reference Data Type Arguments

Reference data type parameters, such as objects, are also passed into methods by value . This means that when the method returns, the passed-in reference still references the same object as before. However , the values of the object's fields can be changed in the method, if they have the proper access level.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值