基于理解的java學(xué)習(xí)筆記之最最基礎(chǔ)部分

          最最基礎(chǔ)部分

          保留關(guān)鍵字:gotoconst

          增加關(guān)鍵字:assertenum

          public class SimpleDemo02{// 聲明一個(gè)類,類名稱的命名規(guī)范:所有單詞的首字母大寫

                 public static void main(String args[]){ // 主方法

                        double x = 30.3 ;    // 聲明小數(shù)

                        float y = 30.3f ;      // 聲明小數(shù)

                 }

          };

          最大加1成最小

          最小減1成最大

          public class SimpleDemo{     // 聲明一個(gè)類,類名稱的命名規(guī)范:所有單詞的首字母大寫

                 public static void main(String args[]){ // 主方法

                        int max = Integer.MAX_VALUE    ;      // 求出整型的最大值

                        int min = Integer.MIN_VALUE ;    // 求出整型的最小值

                        System.out.println("int的最大值:" + max) ;

                        System.out.println("int的最大值 + 1" + (max+1)) ;

                        System.out.println("int的最小值:" + min) ;

                        System.out.println("int的最小值 - 1" + (min-1)) ;

                 }

          }

          數(shù)據(jù)類型的轉(zhuǎn)換:

          public class SimpleDemo03{// 聲明一個(gè)類,類名稱的命名規(guī)范:所有單詞的首字母大寫

                 public static void main(String args[]){ // 主方法

                        char c1 = 'a' ;// 使用”'“括起來表示字符

                        int x1 = c1 ;    // char變?yōu)?/span>int

                        x1++ ;                   // 自增

                        char c2 = (char)x1 ;      // int --> char,進(jìn)行強(qiáng)制轉(zhuǎn)換

                        System.out.println(c2) ;

                 }

          }

          char→int

          byte→short→int→long

          int→float→double

          反過來,需進(jìn)行強(qiáng)制轉(zhuǎn)換

          轉(zhuǎn)換時(shí)如碰到的是字串符,則所有類型都向字串符轉(zhuǎn)換

          public class SimpleDemo04{// 聲明一個(gè)類,類名稱的命名規(guī)范:所有單詞的首字母大寫

                 public static void main(String args[]){ // 主方法

                        String str = "hello " ;      // 表示字符串

                        int i = 10 ;

                        System.out.println(str + (i + 20)) ;

                        System.out.println(1l + 11) ;

                 }

          }

          位操作:指使用二進(jìn)制代碼完成的數(shù)據(jù)操作

          &按位與

          |按位或

          ^異或(相同為0,不同為1

          ~取反

          <<左位移(有符號(hào))

          >>右位移(有符號(hào))

          >>>無符號(hào)右位移

          public class SimpleDemo05{// 聲明一個(gè)類,類名稱的命名規(guī)范:所有單詞的首字母大寫

                 public static void main(String args[]){ // 主方法

                        int x = 3 ;

                        int y = 6 ;

                        System.out.println(x & y) ;

                        System.out.println(x | y) ;

                        System.out.println(x ^ y) ;

                 }

          }

          3的二進(jìn)制代碼:00000000 00000000 00000000 00000011

          6的二進(jìn)制代碼:00000000 00000000 00000000 00000110

          反碼:反碼所有的位按位取反,整數(shù)的反碼就是其本身,負(fù)數(shù)的反碼是用補(bǔ)碼的形式表示出來,再進(jìn)行取反操作,補(bǔ)碼=反碼+1

          public class SimpleDemo06{// 聲明一個(gè)類,類名稱的命名規(guī)范:所有單詞的首字母大寫

                 public static void main(String args[]){ // 主方法

                        int x = -3 ;

                        System.out.println(~x) ;

                 }

          }

          -3的反碼是2

          3的反碼是-4

          public class SimpleDemo07{// 聲明一個(gè)類,類名稱的命名規(guī)范:所有單詞的首字母大寫

                 public static void main(String args[]){ // 主方法

                        int x = 3 ;

                        System.out.println(x<<2) ;    // 左移兩位

                 }

          }

          public class SimpleDemo08{// 聲明一個(gè)類,類名稱的命名規(guī)范:所有單詞的首字母大寫

                 public static void main(String args[]){ // 主方法

                        int x = 3 ;

                        int y = -3 ;

                        System.out.println(x>>2) ;    // 右移兩位

                        System.out.println(y>>2) ;    // 右移兩位

                 }

          }

          public class SimpleDemo09{// 聲明一個(gè)類,類名稱的命名規(guī)范:所有單詞的首字母大寫

                 public static void main(String args[]){ // 主方法

                        int x = 3 ;

                        int y = -3 ;

                        System.out.println(x>>>2) ; // 右移兩位

                        System.out.println(y>>>2) ; // 右移兩位

                 }

          }

          循環(huán)控制

          分支結(jié)構(gòu):ifif…elseif…else if…else

          循環(huán)結(jié)構(gòu):whiledo…whliefor

          循環(huán)控制:breakcontinue

          數(shù)組

          1.       聲明時(shí)直接開辟內(nèi)存空間

          數(shù)據(jù)類型數(shù)組名稱[]=new 數(shù)據(jù)類型[長度];

           數(shù)據(jù)類型 [] 數(shù)組名稱=new 數(shù)據(jù)類型[長度]

          2.分步聲明

          聲明數(shù)組:數(shù)據(jù)類型數(shù)組名稱[]=null;

          實(shí)例化數(shù)組:數(shù)組名稱=new 數(shù)據(jù)類型[長度];

          public class ArrayDemo01{

                 public static void main(String args[]){

                        int i[] = null ;

                        // i = new int[10] ; // 開辟了10個(gè)空間大小的數(shù)組

                        System.out.print("數(shù)組開辟之后的內(nèi)容:") ;

                        for(int x=0;x<i.length;x++){

                               System.out.print(i[x] + "") ;

                        }

                        i[0] = 30 ;       // 為第一個(gè)元素賦值

                        i[9] = 60 ;       // 為最后一個(gè)元素賦值

                        System.out.print(""n數(shù)組賦值之后的內(nèi)容:") ;

                        for(int x=0;x<i.length;x++){

                               System.out.print(i[x] + "") ;

                        }

                 }

          }

          為數(shù)組的元素賦值,需通過下標(biāo)的形式進(jìn)行訪問

          靜態(tài)初始化:

          public class ArrayDemo02{

                 public static void main(String args[]){

                        int i[] = {1,2,3,4,6,7} ; // 此時(shí)屬于靜態(tài)初始化

                        System.out.print("數(shù)組開辟之后的內(nèi)容:") ;

                        for(int x=0;x<i.length;x++){

                               System.out.print(i[x] + "") ;

                        }

                 }

          }

          二維數(shù)組

          public class ArrayDemo03{

                 public static void main(String args[]){

                        int i[][] = {{1,2},{2,3,4},{3,4,5,6,7}} ;      // 此時(shí)屬于靜態(tài)初始化

                        System.out.print("數(shù)組開辟之后的內(nèi)容:") ;

                        for(int x=0;x<i.length;x++){

                               for(int y=0;y<i[x].length;y++){

                                      System.out.print(i[x][y] + "") ;

                               }

                               System.out.println("") ;

                        }

                 }

          }

          主方法之外的方法:可重復(fù)調(diào)用的代碼段

          public class MethodDemo01{

                 public static void main(String args[]){

                        print() ;          // 調(diào)用方法

                        print() ;          // 調(diào)用方法

                        print() ;          // 調(diào)用方法

                 }

                 public static void print(){

                        System.out.println("Hello World!!!") ;

                 }

          }

          public class MethodDemo02{

                 public static void main(String args[]){

                        System.out.println(add(10,20)) ;

                        System.out.println(add(30,30)) ;

                 }

                 public static int add(int x ,int y){

                        int temp = x + y ;

                        return temp ;   // 將計(jì)算結(jié)果返回

                 }

          }

          此內(nèi)容包含方法的重載

          指過程中調(diào)用的方法名稱相同,但是參數(shù)的類型或個(gè)數(shù)不同(同樣方法也被聲明多個(gè),但方法都相同)

          public class MethodDemo03{

                 public static void main(String args[]){

                        System.out.println(add(10,20)) ;

                        System.out.println(add(30,30)) ;

                        System.out.println(add(30,30,30)) ;

                        System.out.println(add(30.03f,30.01f)) ;

                 }

                 public static int add(int x ,int y){

                        int temp = x + y ;

                        return temp ;   // 將計(jì)算結(jié)果返回

                 }

                 public static int add(int x ,int y,int z){

                        int temp = x + y + z ;

                        return temp ;   // 將計(jì)算結(jié)果返回

                 }

                 public static float add(float x ,float y){

                        float temp = x + y ;

                        return temp ;   // 將計(jì)算結(jié)果返回

                 }

          }

          public class MethodDemo04{

                 public static void main(String args[]){

                        System.out.println(1) ;

                        System.out.println("hello") ;

                        System.out.println(1.1) ;

                        System.out.println('c') ;

                 }

          }

          System.out.println()可接受任意形式的參數(shù),屬于方法的重載

          但要注意

          public class MethodDemo05{

                 public static void main(String args[]){

                 }

                 public static int add(int x ,int y){

                        int temp = x + y ;

                        return temp ;   // 將計(jì)算結(jié)果返回

                 }

                 public static float add(int x ,int y){

                        float temp = x + y ;

                        return temp ;   // 將計(jì)算結(jié)果返回

                 }

          }

          不是方法的重載,因?yàn)榇饲闆r下雖然返回值不同,但參數(shù)的類型和個(gè)數(shù)相同

          return的使用:使用return結(jié)束一個(gè)方法的操作,當(dāng)執(zhí)行到return時(shí)直接返回到方法調(diào)用處繼續(xù)執(zhí)行

          public class MethodDemo06{

                 public static void main(String args[]){

                        fun(10) ;

                        fun(3) ;

                 }

                 public static void fun(int x){

                        System.out.println("進(jìn)入方法。") ;

                        if(x==3){

                               return ;// 返回方法的被調(diào)用處

                        }

                        System.out.println("結(jié)束方法。") ;

                 }

          }

          遞歸調(diào)用:自己調(diào)用自己

          public class MethodDemo07{

                 public static void main(String args[]){

                        int sum = 0 ;

                        for(int i=0;i<=100;i++){

                               sum += i ;      // 累加操作

                        }

                        System.out.println("計(jì)算結(jié)果:" + sum) ;

                 }

          }

          但遞歸操作通常要有明確的截止條件,否則會(huì)出現(xiàn)異常

          public class MethodDemo08{

                 public static void main(String args[]){

                        int sum = 0 ;

                        sum = fun(100) ;

                        System.out.println("計(jì)算結(jié)果:" + sum) ;

                 }

                 public static int fun(int temp){

                        if(temp==1){

                               return 1 ;

                        }else{

                               return temp + fun(temp-1) ;

                        }

                 }

          }

          方法與數(shù)組

          方法中對(duì)數(shù)組所作的一切修改,最終都會(huì)被保留下來

          public class MethodArrayDemo01{

                 public static void main(String args[]){

                       int temp[] = {1,3,5,7,9} ;      // 聲明數(shù)組

                        fun(temp) ;

                        print(temp) ;

                 }

                 public static void fun(int []x){

                        x[0] = 6 ;       // 修改第一個(gè)元素

                 }

                 public static void print(int[] x){

                        for(int i=0;i<x.length;i++){

                               System.out.print(x[i] + "") ;

                        }

                 }

          }

          使用方法可以返回一個(gè)數(shù)組,只要在返回值類型上加入數(shù)組類型即可

          public class MethodArrayDemo02{

                 public static void main(String args[]){

                       int temp[] = fun() ;// 聲明數(shù)組

                        print(temp) ;

                 }

                 public static int[] fun(){

                        int x[] = {1,3,5,7,9} ;

                        return x ;// 返回?cái)?shù)組

                 }

                 public static void print(int[] x){

                        for(int i=0;i<x.length;i++){

                               System.out.print(x[i] + "") ;

                        }

                 }

          }

          排序操作

          public class MethodArrayDemo03{

                 public static void main(String args[]){

                       int temp[] = fun() ;// 聲明數(shù)組

                        java.util.Arrays.sort(temp) ;      // 進(jìn)行排序操作

                        print(temp) ;

                 }

                 public static int[] fun(){

                        int x[] = {23,1,5,3,24,3,56,4,3,1} ;

                        return x ;// 返回?cái)?shù)組

                 }

                 public static void print(int[] x){

                        for(int i=0;i<x.length;i++){

                               System.out.print(x[i] + "") ;

                        }

                 }

          }

          拷貝操作

          public class MethodArrayDemo04{

                 public static void main(String args[]){

                       int t1[] = {1,2,3,4,5,6,7,8,9} ;

                        int t2[] = {11,22,33,44,55,66,77,88,99} ;

                        // 源數(shù)組名稱下標(biāo)目標(biāo)數(shù)組下標(biāo)拷貝長度

                        System.arraycopy(t2,0,t1,3,3) ; // 數(shù)組拷貝

                        print(t1) ;

                 }

                 public static void print(int[] x){

                        for(int i=0;i<x.length;i++){

                               System.out.print(x[i] + "") ;

                        }

                 }

          }

          新特性對(duì)數(shù)組的支持

          foreach

          for(數(shù)據(jù)類型變量:數(shù)組){

             //操作

          }

          public class MethodArrayDemo05{

                 public static void main(String args[]){

                       int t1[] = {1,2,3,4,5,6,7,8,9} ;

                        for(int x:t1){

                               System.out.print(x + "") ;

                        }

                 }

          }

          可變參數(shù)

          聲明方法參數(shù)時(shí),參數(shù)個(gè)數(shù)不固定,則使用也不固定

          public static 返回值類型數(shù)組名稱(數(shù)據(jù)類型參數(shù)名稱)

          public class MethodArrayDemo06{

                 public static void main(String args[]){

                        int temp[] = {2,4,6,8} ;

                       fun() ;            // 沒有參數(shù)

                       fun(1) ;   // 一個(gè)參數(shù)

                       fun(1,3,5,7,9) ;      // 一個(gè)參數(shù)

                        fun(temp) ;

                 }

                 public static void fun(int ... arg){

                        for(int x:arg){

                               System.out.print(x + "") ;

                        }

                        System.out.println() ;

                 }

          }

          對(duì)象的創(chuàng)建及使用

          類通過屬性建立模型,而對(duì)象將模型實(shí)例化,方法則是完成任務(wù)使用的便利工具

          類名對(duì)象名稱=null;    //聲明對(duì)象

          對(duì)象名稱=new 類名();    //實(shí)例化對(duì)象

          或直接實(shí)例化   類名對(duì)象名稱=new 類名();

          class Person{

                 String name    ;      // 表示人的姓名

                 int age ;          // 表示人的年齡

                 public void tell(){   // 定義說話的方法

                        System.out.println("姓名:" + name + ",年齡:" + age) ;

                 }

          };

          public class OODemo02{

                 public static void main(String args[]){

                        Person per = new Person() ; // 產(chǎn)生實(shí)例化對(duì)象

                 }

          }

          訪問類中的屬性和方法

          訪問屬性:對(duì)象名稱.屬性名=

          訪問方法:對(duì)象名稱.方法()

          class Person{

                 String name    ;      // 表示人的姓名

                 int age ;          // 表示人的年齡

                 public void tell(){   // 定義說話的方法

                        System.out.println("姓名:" + name + ",年齡:" + age) ;

                 }

          };

          public class OODemo03{

                 public static void main(String args[]){

                        Person per = new Person() ; // 產(chǎn)生實(shí)例化對(duì)象

                        per.name = "張三" ;              // 為名字賦值

                        per.age = 30 ;                // 為年齡賦值

                        per.tell() ;                     // 調(diào)用方法

                 }

          }

          引用傳遞

          將一個(gè)堆內(nèi)存空間的使用權(quán)交給其他對(duì)象,相當(dāng)于為一個(gè)堆內(nèi)存空間起了一個(gè)別名

          class Person{

                 String name    ;      // 表示人的姓名

                 int age ;          // 表示人的年齡

                 public void tell(){   // 定義說話的方法

                        System.out.println("姓名:" + name + ",年齡:" + age) ;

                 }

          };

          public class OODemo06{

                 public static void main(String args[]){

                        Person per1 = null ;       // 聲明對(duì)象

                        Person per2 = null ;       // 聲明對(duì)象

                        per1 = new Person() ;    // 實(shí)例化對(duì)象

                        per2 = per1 ;                 // 引用傳遞

                        per1.name = "張三" ;            // 為名字賦值

                        per1.age = 30 ;                     // 為年齡賦值

                        per2.age = 33 ;

                        per1.tell() ;                   // 調(diào)用方法

                        per2.tell() ;

                 }

          }

          class Person{

                 String name    ;      // 表示人的姓名

                 int age ;          // 表示人的年齡

                 public void tell(){   // 定義說話的方法

                        System.out.println("姓名:" + name + ",年齡:" + age) ;

                 }

          };

          public class OODemo07{

                 public static void main(String args[]){

                        Person per1 = null ;       // 聲明對(duì)象

                        Person per2 = null ;       // 聲明對(duì)象

                        per1 = new Person() ;    // 實(shí)例化對(duì)象

                        per2 = new Person() ;    // 實(shí)例化對(duì)象

                        per2.name = "李四" ;    

                        per2 = per1 ;                 // 引用傳遞

                        per1.name = "張三" ;            // 為名字賦值

                        per1.age = 30 ;                     // 為年齡賦值

                        per2.age = 33 ;

                        per1.tell() ;                   // 調(diào)用方法

                        per2.tell() ;

                 }

          }

          一個(gè)棧內(nèi)存只能引用一個(gè)堆內(nèi)存,但一個(gè)堆內(nèi)存中可以被多個(gè)棧內(nèi)存所指向

          封裝屬性:private 數(shù)據(jù)類型屬性名稱=默認(rèn)值;

          封裝方法:private 返回值類型|void 方法名稱(參數(shù)列表)

          class Person{

                 private String name;      // 表示人的姓名

                 private int age ;             // 表示人的年齡

                 public void tell(){   // 定義說話的方法

                        System.out.println("姓名:" + name + ",年齡:" + age) ;

                 }

          };

          public class OODemo09{

                 public static void main(String args[]){

                        Person per = new Person() ; // 實(shí)例化對(duì)象

                        per.name = "張三" ;              // name屬性賦值

                        per.age = -30;

                        per.tell() ;

                 }

          }

          無法執(zhí)行

          固有:只要屬性就必須封裝,被封裝的屬性通過settergetter方法設(shè)置和取得

          class Person{

                 private String name;      // 表示人的姓名

                 private int age ;             // 表示人的年齡

                 public void tell(){   // 定義說話的方法

                        System.out.println("姓名:" + this.getName() + ",年齡:" + this.getAge()) ;

                 }

                 public void setName(String n){

                        name = n ;

                 }

                 public void setAge(int a){

                        if(a>=0&&a<=200){

                               age = a ;

                        }

                 }

                 public String getName(){

                        return name ;

                 }

                 public int getAge(){

                        return age ;

                 }

          };

          public class OODemo10{

                 public static void main(String args[]){

                        Person per = new Person() ; // 實(shí)例化對(duì)象

                        per.setName("張三") ;           // name屬性賦值

                        per.setAge(-30);

                        per.tell() ;

                 }

          }

          this.方法()→調(diào)用本類方法

          類的圖形,power designer工具

          構(gòu)造方法,為類中屬性進(jìn)行初始化,每一個(gè)類中都存在一個(gè)構(gòu)造方法

          構(gòu)造方法必與類名一致,定義時(shí)不能有返回值聲明,也不能在中用return返回一個(gè)內(nèi)容

          class Person{

                 private String name;      // 表示人的姓名

                 private int age ;             // 表示人的年齡

                 public Person(){            // 定義了一個(gè)構(gòu)造方法

                        System.out.println("******************") ;

                 }

                 public void tell(){   // 定義說話的方法

                        System.out.println("姓名:" + this.getName() + ",年齡:" + this.getAge()) ;

                 }

                 public void setName(String n){

                        name = n ;

                 }

                 public void setAge(int a){

                        if(a>=0&&a<=200){

                               age = a ;

                        }

                 }

                 public String getName(){

                        return name ;

                 }

                 public int getAge(){

                        return age ;

                 }

          };

          public class OODemo11{

                 public static void main(String args[]){

                        Person per = null ;

                        per = new Person() ;     // 實(shí)例化對(duì)象

                        /*

                        per.setName("張三") ;           // name屬性賦值

                        per.setAge(30);

                        per.tell() ;

                 */

                 }

          }

          class Person{

                 private String name;      // 表示人的姓名

                 private int age ;             // 表示人的年齡

                 public Person(){}

                 public Person(String n){

                        this.setName(n) ;

                 }

                 public Person(String n,int a){              // 定義了一個(gè)構(gòu)造方法

                        this.setName(n) ;    // 調(diào)用setName()方法

                        this.setAge(a) ;              // 調(diào)用setAge()方法

                        System.out.println("******************") ;

                 }

                 public void tell(){   // 定義說話的方法

                        System.out.println("姓名:" + this.getName() + ",年齡:" + this.getAge()) ;

                 }

                 public void setName(String n){

                        name = n ;

                 }

                 public void setAge(int a){

                        if(a>=0&&a<=200){

                               age = a ;

                        }

                 }

                 public String getName(){

                        return name ;

                 }

                 public int getAge(){

                        return age ;

                 }

          };

          public class OODemo12{

                 public static void main(String args[]){

                        Person per = null ;

                        per = new Person("張三",-30) ;    // 實(shí)例化對(duì)象

                        per.tell() ;

                 }

          }

          匿名對(duì)象,只使用一次的對(duì)象

          class Person{

                 private String name;      // 表示人的姓名

                 private int age ;             // 表示人的年齡

                 public Person(){}

                 public Person(String n){

                        this.setName(n) ;

                 }

                 public Person(String n,int a){              // 定義了一個(gè)構(gòu)造方法

                        this.setName(n) ;    // 調(diào)用setName()方法

                        this.setAge(a) ;              // 調(diào)用setAge()方法

                        System.out.println("******************") ;

                 }

                 public void tell(){   // 定義說話的方法

                        System.out.println("姓名:" + this.getName() + ",年齡:" + this.getAge()) ;

                 }

                 public void setName(String n){

                        name = n ;

                 }

                 public void setAge(int a){

                        if(a>=0&&a<=200){

                               age = a ;

                        }

                 }

                 public String getName(){

                        return name ;

                 }

                 public int getAge(){

                        return age ;

                 }

          };

          public class OODemo13{

                 public static void main(String args[]){

                        new Person("張三",-30).tell() ;

                 }

          }

          使用

          class Student{

                 private String name ;

                 private int age ;

                 private float english ;

                 private float computer ;

                 private float math ;

                 public Student(){}

                 public Student(String n,int a,float e,float c,float m){

                        this.setName(n) ;

                        this.setAge(a) ;

                        this.setEnglish(e) ;

                        this.setComputer(c) ;

                        this.setMath(m) ;

                 }

                 public float sum(){

                        return english + computer + math ;

                 }

                 public float avg(){

                        return this.sum() / 3 ;

                 }

                 public float max(){

                        float max = computer>math?computer:math ;

                        max = max>english?max:english ;

                        return max ;

                 }

                 public float min(){

                        float min = computer<math?computer:math ;

                        min = min<english?min:english ;

                        return min ;

                 }

                 public String getInfo(){

                        return      "學(xué)生信息: "n" +

                                      ""t|- 姓名:" + this.getName() + ""n" +

                                      ""t|- 年齡:" + this.getAge() + ""n" +

                                      ""t|- 數(shù)學(xué)成績:" + this.getMath() + ""n" +

                                      ""t|- 英語成績:" + this.getEnglish() + ""n" +

                                      ""t|- 計(jì)算機(jī)成績:" + this.getComputer() ;

                 }

                 public void setName(String n){

                        name = n ;

                 }

                 public void setAge(int a){

                        age = a ;

                 }

                 public void setEnglish(float e){

                        english = e ;

                 }

                 public void setComputer(float c){

                        computer = c ;

                 }

                 public void setMath(float m){

                        math = m ;

                 }

                 public String getName(){

                        return name ;

                 }

                 public int getAge(){

                        return age ;

                 }

                 public float getEnglish(){

                        return english ;

                 }

                 public float getComputer(){

                        return computer ;

                 }

                 public float getMath(){

                        return math ;

                 }

          }

          public class ExecDemo{

                 public static void main(String args[]){

                        Student stu = new Student("張三",30,89.0f,91.0f,87.0f) ;

                        System.out.println("總分:" + stu.sum()) ;

                        System.out.println("平均分:" + stu.avg()) ;

                        System.out.println("最高分:" + stu.max()) ;

                        System.out.println("最低分:" + stu.min()) ;

                        System.out.println(stu.getInfo()) ;

                 }

          }

          class Address {

                 private String national ;

                 private String province ;

                 private String city ;

                 private String street ;

                 private String zipcode ;

                 public Address(){}

                 public Address(String n,String p,String c,String s,String z){

                        this.setNational(n) ;

                        this.setProvince(p) ;

                        this.setCity(c) ;

                        this.setStreet(s) ;

                        this.setZipcode(z) ;

                 }

                 public String getInfo(){

                        return      "地址信息:" + ""n" +

                                      ""t|- 國家:" + this.getNational() + ""n" +

                                      ""t|- 省份:" + this.getProvince() + ""n" +

                                      ""t|- 城市:" + this.getCity() + ""n" +

                                      ""t|- 街道:" + this.getStreet() + ""n" +

                                      ""t|- 郵編:" + this.getZipcode() ;                         

                 }

                 public void setNational(String n){

                        national = n ;

                 }

                 public void setProvince(String p){

                        province = p ;

                 }

                 public void setCity(String c){

                        city = c ;

                 }

                 public void setStreet(String s){

                        street = s ;

                 }

                 public void setZipcode(String z){

                        zipcode = z ;

                 }

                 public String getNational(){

                        return national ;

                 }

                 public String getProvince(){

                        return province ;

                 }

                 public String getCity(){

                        return city ;

                 }

                 public String getStreet(){

                        return street ;

                 }

                 public String getZipcode(){

                        return zipcode ;

                 }

          };

          public class AddressDemo{

                 public static void main(String args[]){

                        Address add = new Address("中國","北京","北京市","西城區(qū)","100088") ;

                        System.out.println(add.getInfo()) ;

                 }

          }

          posted on 2009-07-29 18:20 swedenborg 閱讀(312) 評(píng)論(1)  編輯  收藏

          評(píng)論

          # re: 基于理解的java學(xué)習(xí)筆記之最最基礎(chǔ)部分[未登錄] 2009-07-30 13:37 test

          確實(shí)很基礎(chǔ)  回復(fù)  更多評(píng)論   


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          <2009年7月>
          2829301234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 望谟县| 定边县| 太康县| 会昌县| 磴口县| 孟州市| 青冈县| 故城县| 吉隆县| 周宁县| 商南县| 桐庐县| 商城县| 泾阳县| 南涧| 长春市| 景泰县| 正镶白旗| 三原县| 秦安县| 丰都县| 连山| 龙岩市| 长乐市| 正安县| 绿春县| 花垣县| 津市市| 万载县| 临泉县| 福清市| 托里县| 温泉县| 那坡县| 玉山县| 桓仁| 双牌县| 海原县| 山东省| 新龙县| 兴隆县|