overload n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Overload PowerPoint Presentation
Download Presentation
Overload

Loading in 2 Seconds...

play fullscreen
1 / 13

Overload - PowerPoint PPT Presentation


  • 104 Views
  • Uploaded on

Overload. Overload ( 多載 , 重載 ) -- 只要 method signature( 方法簽章 ) 不一樣 , 雖然名稱一樣 , 也可以成立 Signature : 方法名稱雖一樣 但 引數個數 不一樣 或 引數資料型態 對應不一樣. Method 的語法. Declaring Classes( 宣告類別 ). 宣告類別 : 告訴他人我這個類別將有哪些屬性及方法

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Overload' - ordell


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
overload
Overload

Overload (多載, 重載) --只要method signature(方法簽章) 不一樣, 雖然名稱一樣, 也可以成立

Signature:

方法名稱雖一樣

但引數個數不一樣 或

引數資料型態對應不一樣

declaring classes
Declaring Classes(宣告類別)
  • 宣告類別: 告訴他人我這個類別將有哪些屬性及方法
  • extends: 繼承, 下面例子MyClass可以延用MySuperClass的方法implements實作, 下面例子MyClass要將YourInterface中所宣告的方法, 完成定義
declaring member variables
Declaring Member Variables (宣告變數及方法)
  • Member variables in a class(在類別大括號之間宣告的變數稱為)—these are called fields(屬性).
  • Variables in a method or block of code(在方法-及副程式大括號之間宣告的變數稱為)—these are called local variables 區域變數().
  • Variables in method declarations(在方法-及副程式圓括號之間宣告的變數稱為)—these arecalled parameters(參數).
  • Access Modifiers(修飾元)

 public modifier(公用)—the field is accessible from all classes 所有其他類別皆可用到.

 private modifier(私有)—the field is accessible only within its own class 只有自己的類別內部的成員, 如屬性和方法, 才能用.

constructor
建構元Constructor
  • 建構元: 建立物件的方法
  • 建構元是特殊的方法, 不傳回任何型態, 也不傳回 void

  • 若類別本身沒有建構元, compiler 會給予一個預設建構元=> 類別名稱(){}
abstract class
abstract class(抽象類別)
  • 抽象類別必須以abstract宣告
  • 類別其中有一個方法為abstract =>沒有實作{}, 就必須宣告為abstract.
  • 但也可全部方法都不是abstract
  • abstract class主要不讓 使用者建立物件
  • 抽象類別不能被New起來 (ch11, p11)
  • 繼承抽象類別的類別必須將方法補齊 (ch11, p8)
override overload http 192 192 246 169 wells wiki index php scjp 1 6 e7 89 88 e8 80 83 e9 a1 8c 012
Override&Overload 練習http://192.192.246.169/~wells/wiki/index.php/SCJP_1.6%E7%89%88%E8%80%83%E9%A1%8C_012
override overload
Override&Overload 練習
  • http://nikojava.wordpress.com/2008/10/10/free-scjp-mock-exams/
override
Override 練習
  • Explanation:
  • An overriding method can throw the same exceptions(相同的例外), narrower exceptions(範圍較小的例外), or no exceptions (無例外)and can throw any runtime exceptions(可以丟出RUNTIME例外)whether they were listed in the overridden method or not.
  • An overriding method cannot reduce the access scope of the overridden method but can widen it.
override http www tutorialspoint com java java overriding htm
Override 練習http://www.tutorialspoint.com/java/java_overriding.htm
override2
Override 練習

import java.io.*;

class Test

{

public void display() throws IOException { }

}

public class Demo extends Test

{

public void display() throws Exception { } // throwing super class exception

}

//error, why

override3
Override 練習

import java.io.*;

class Test {

public void display() throws IOException { }

}

public class Demo extends Test {

public void display() throws IOException { }

}