JAVA ????? - PowerPoint PPT Presentation

About This Presentation
Title:

JAVA ?????

Description:

JAVA 6 6 - 1. (Inheritance of class) (1/6) ... – PowerPoint PPT presentation

Number of Views:68
Avg rating:3.0/5.0
Slides: 35
Provided by: tis140
Category:

less

Transcript and Presenter's Notes

Title: JAVA ?????


1
JAVA ?????
6? ?????????? ??
2
????
? ???? ????????? ?? ??? ??? ??? ???? ???? ??? ??
????, ??? ??? ??? ??? ? ?? ???? ????, ?????,
????? ?????? ? ?? ??? ?? ??? ?? ??????? ?? ????.
??
Section1 ??? ??(Inheritance of class) Section2
???(polymorphism) Section3 ?????(abstract class)
Section4 ?????(interface) Section5 static ?
final Section6 ?? ???(inner class) Section7
??????
3
6?-???? ?????? ??
Section1 ??? ??(Inheritance of class)
????? ????? ???? ??? ?? ???? .
Section2 ???(polymorphism)
??? ??? ???? ?? ???? ?? ???? .
Section3 ?????(abstract class)
??? ???? ?? ?????? ?? ????.
Section4 ?????(interface)
?? ??? ?? ?????? ?? ????.
static? final???? ?? ????.
Section5 static ? final
????? ?? ?? ?? ???? ?? ????.
Section6 ?? ???(inner class)
Vector, Wrapper? ?????? ?????? ?? ????.
Section7 ??????
4
1. ??? ??(Inheritance of class) (1/6)
  • ??(inheritance) (1/3)
  •  ??????? ?? ??? ??? ???? ?????? ???? ????.
  • ??? ???? ??? ? ???? ?? ???? ?? ???, ??? ???
    ?????? ???? ??? ????? ??? ? ??. ??? ?? ??? ???
    ????? ???? ??? ???? ??????? ??.
  • ????? ??? ?? ??? ?? ???? ???? ????? ???, ??? ???
    ??? ? ??, ?? ? ????? ????? ???? ????? ???? ???
    ????  ? ?????.

5
1. ??? ??(Inheritance of class) (2/6)
  • ??(inheritance) (2/3)
  •  ?? ???? ??? ??? ??? ?? ???? ??? ?? ???
  • ?????(sub class), ?????(child class),
    ?????(derived class)
  • ??? ?? ????? ????? ???
  • ?????(super class), ??????(base class),
    ?????(parent class)
  • ?? ?????? ??? extends?? ???? ?? ????.

6
1. ??? ??(Inheritance of class) (3/6)
  • ??(inheritance) (3/3)
  • ??? "is a"??? ????. 
  • "Human is a Mammal." ???? ?? ? ????? ??? ???
    ???(???)?? ????. ??? ??? ???? ???(???)??? ???.
  • extends? ???? ??? ????? ?? ???? ????? ??

class Mammal //Mammal??? ??    void eat()    class Human extends Mammal //Human??? ?? ...
7
1. ??? ??(Inheritance of class) (4/6)
  • super ????
  • super ????? ?????? ???? ??????
  • super()???
  • super()???? ?????? ???? ????.
  • this ????? super ????? static? ?? ?????? ?? ? ?
    ??. ??? main()?????? ??? ??? ? ??.

8
1. ??? ??(Inheritance of class) (5/6)
  • ?????(overriding) (1/2)
  • ?????? ?????? ?????, ??????? ???? ???? ??? ????
    ?? ???, ?????? ??? ??? ???? ?? ???.
  • ?????? ?????? ?? ??? ?? ???? ??? ?, ?????? ????
    ????(override), ?????? ???? ???? ???, ???? ? ????
    ???.

9
1. ??? ??(Inheritance of class) (6/6)
  • ?????(overriding) (2/2)
  • ?????? ???
  • ? ?? ?????? ???? ??????? ?????? ????, ???? ?????
    ?? ?? ???? ???? ??. ???? ??? ?????? ?? ???.
  • ? ?? ??????? ??? ?? ???? ?????? ?????? ???????
    ???? ????? ? ???, ? ???? ?????? ????.

10
2. ???(polymorphism) (1/2)
  • ???? ???? ??? ????? ???? ???? ??? ?????? ?????
    ????.
  • '???'? ?? ?? ?? ?? ??? ??? ???? ???,  ???? ????
    ??? ??? ?? ?? ?? ??? ????? ? ? ??.
  • ??? ??? ??? ??? ???? ???? ???? ????, ??? ????
    ????? ??? ? ?? ???? ??? ????? ?? ??? ???? ???

11
2. ???(polymorphism) (2/2)
  • ????? ??????? , ???? ??? ?????? ????, ???? ??????
    ?? ??? ?? ??? ??? ??? ??? ? ??.

12
3. ?????(abstract class) (1/4)
  • ????? ??? ??? ??? ?? ??(body )? ??  ???? ????.
    ???? ??? ?? ???? ?? ??? ??? ??? ??? ???? ?? ? ??.
  • ???? ??? ??? ?? ?? ???? ????? ??(???)? ?? ?? 
    ???? ???? ??? ? ???? ?????? ???.
  • ?? ???? ???? ???? ?? ?? ???? ?????? ??. ??????
    ???? ??? ??? (????)? ??.

13
3. ?????(abstract class) (2/4)
  • ?????? ??? ??? ? ??.
  • ??? ????? ???? ??? ?? ???? ?? ??? ??? ??? ??.
  • ?????? ??? ??? ????? ???. ?????? ??? abstract????
    ?? ????.

public class AbstractClass //?????? ??.   int abc()     ...     public void test(int x) //?????
14
3. ?????(abstract class) (3/4)
  • ?????? ???? ???? ?????? ?????? ?? ??????? ??.
    ?????? ?? ??? ??? ????.
  • ?????? ? ???? ???? ???? ????? ??? ??? ??? ? ??? ?
    ??? ?? ?? ?? ??? ????? ???? ? ? ? ?? ??? ??? ???
    ?? ??? ??? ???? ?? ???? ??? ????? ???
    ??(implements)??? ???? ??? ????. ????? ???? ??
    ???? ??? ?????? ???? ??? ????? ??.

15
3. ?????(abstract class) (4/4)
  • ?????? ??
  • ???? ?? ?? (????) ?? ?????. ???????? ??? ?? ??
    ?????? ????? ??? ???? ??. ??? ?????? ??????? ??.

????? abstract ???? ????(???????)
16
4. ?????(interface) (1/3)
  • ??? ????? ???? ???.
  • ???? ???? ????? ?? ?????? ????? ?????? ?????
    ????? ?????? ????.
  • ?????? ??(spec)?? ??? ?? ??? ?????? ????? ?????
    ?????? ????? ??.
  • ?, ???? ?????? ????? ????, ????? ?? ??? ? ????
    ??? ??? ??? ??? ??? ??? ??.
  • ?????? ??? ?? ???? ?? ???????? ?????? ???? ?????
    ?? ???? ??? ?? ????? ?? ??? ???.

17
4. ?????(interface) (2/3)
  • ?????? ???? ???? ?? public abstract??. ?, public
    abstract? ???? ??? ???? ??? ???.
  • ?????? ????? ?? public static final??. ??? ?????
    ??? ???? ?? ???? ??? ??. ?? ?????? public
    abstract? ??? ???.
  • ?????? interface?? ???? ????.

interface Draw //????? ??    int x5  //????    public abstract test() //?????
18
4. ?????(interface) (3/3)
  • ?????? implements? ???? ??? ??? ????. ?????? ????
    ?? extends??? implements? ????.
  • ?? ?? ?????? implements?? ? ??.  ?? ?? ??????
    implements?? ?? ?? ?? ??????? ??(,)? ???????? ??.
    ???? ??????? ?? ??? ?? ???? ??? ??.

public class A extends B implements C
public class A extends B implements C,D,E
19
5. static ? final (1/4)
  • final ???
  • final? ???? ?? ??? ? ???? ??? ?? ? ??. ? ???? ???
    ??? ???? ??? ? ??? ???. ???  final? ???? ??? ?
    ??? ?? ?? ????. 
  • final? ?? ???? ?? ???? ???? ???? ??? ????.
  • final ???
  • ???? final? ??? ???? ? ???? ?????? ?? ???. ??????
    ??? ?? ??? ??.

20
5. static ? final (2/4)
  • final ????
  • final? ???? ????? ????, ????? ?? ??? ? ?? ????
    ????.
  • final ????? ????? ? ??, ??? ?? ??? ? ??.
  • ??? final? ?? ????? ??? ???? ?? ??. ??? ?? ????
    ??? ??? ????. ????? final? ?? ????? static? ??
    ???? ??.

21
5. static ? final (3/4)
  • static ???
  • static? ??? ???? ?????? ?? ?? ??? ??? ????. ??
    static?? ??? ???? ??? ????? ?? ??? ???? ???? ???
    ? ??.
  • static ????
  • ????? ??? ?????? ????? ????. ??? static? ??? ??
    ??? ??? ?? ?????? ??? ? ??. ?, ? ?? ??? ?? ????
    ???? ???? ?? ??? ????. ??? ??? ???????? ???.

22
5. static ? final (4/4)
  • static ??? ??(static initial block)
  • ????? static???? ????, ??? ???? ??? ? ??. 
    static??? ??? ???? ???? ? ????, main()????? ??
    ????.

23
6. ?? ???(inner class) (1/5)
  • ????? ????? ?????? ?????? ?? ???? ???? ? ??? ??.
  • ?? ?????? ?? ?? ???? ?????? ??.
  • ?????(?????nested class)? ?????(Outer class)? ??
    ??(???, ????? ??)? ?? ???? ??? ??.
  • ?????? ?? ?????? ????? ????? ?? ?? ???, ?????
    ????? ???? ??? ?????? ?? ????.

24
6. ?? ???(inner class) (2/5)
  • static ?????(static inner class)
  • static ?????(static inner class)? ?????? ???
    ?????? ?? ????? ?? ? ????. static???? ?? ??????,
    ????? ????? ??? ???? ????.
  • ?? ????? Outer??? ??? ???? Inner???? ???? ??? ???
    ??? ? ??? ?? ??? ????.

public class Outer      public static class Inner            //Inner ???? ??         //Outer ???? ??
Outer.Inner ex new Outer.Inner()
25
6. ?? ???(inner class) (3/5)
  • non-static ?????( non-static inner class)
  • non-static ?????? static?????? ???? ??? ???
    static? ???? ?? ???????.
  • ?? ????? Outer???? ?????? Inner???? ???? ??? ???
    ??? ?? ?? ?????? ??? ???? ? ????? ??? ?????? ???
    ????.

public class Outer      public  class Inner           //Inner???? ??              //Outer???? ??
Outer out new Outer()  //?????? Outer???? ?? out?? Outer.Inner in out.new Inner()  //?????? Inner???? ?? in ??
26
6. ?? ???(inner class) (4/5)
  • ???????(local inner class)
  • static? non-static?????? ?????? ??? ??? ???? ??
    ??, ???????? ?????? ????? ??? ???????.

public class LocalInnerClass // ?????      int i10      void outerMethod()             class Inner // ???????                   final int x10                   String innerMethod()                      return i" StaticInnerClass"                                 
27
6. ?? ???(inner class) (5/5)
  • ?? ?????(anonymous inner class)
  • ???????? ???????? ????? ????? ?? ?? ??? ??? ? ??.
    ?? ??????? ?? ????.

window.addWindowListener( new
WindowAdapter() //???????             public
void windowClosing( WindowEvent e )
                System.exit( 0 )
                    )
28
7. ?????? (1/7)
  • Wrapper ???
  • ???? ????? ???? ?? ?? ?????(primitive data type)?
    int, double, char??? ??? ???? ?? ? ?? ??.

?? ?????(primitive data type) Wrapper ???
byte Byte
short Short
int Integer
long Long
float Float
double Double
boolean Boolean
char Character
29
7. ?????? (2/7)
  • Vector ???(1/3)
  • ???? ??? ??? ??? ?? ?? Vector?????. ???????? ???
    ???? ??? ? Vector???? ????.
  • Vector???? ?? ??? ??? ??????, ?? ???? ?(????? ?
    ?)?? ???.
  • Vector? Object???? ?????? ????? ???? ??.  ??? ??
    ????? ??? ?? ????? Vector? ??? ? ??.
  • Vector? ????? ??(int, float , short , double ,
    byte , char , boolean)? ???? ???. ????? ??? ????
    ??? Wrapper???? ???? ??.

30
7. ?????? (3/7)
  • Vector ???(2/3)
  • Vector???? java.util???? ????. Vector? ?????
    java.util ???? import?? ??.
  • Vector???? ???? ?? ???? ???

public Vector() ??? 10? ???? public Vector(int initialCapacity) ??? initialCapacity? ???? public Vector(int initialCapacity, int capacityIncrement) ??? initialCapacity? ??? ????,  ??? ??? ??? ??? capacityIncrement? ????.
31
7. ?????? (4/7)
  • Vector ???(3/3)
  • Vector? ???? ?? ???? ???

public int capacity() ??? ??(??)? ??(??)??. public int size() ???? ??? ????(??)? ?? ??(??)??. public void addElement(Object element) ??? ?? ????? ????. public void removeElement(Object element) ???? ?? ???? ????? ????. public void trimToSize() ??? capacity(??)? ?? ??? ???? ?? ????? ?(size)?? ???. ??? ??? ??? ??? ???? ?????. public Object elementAt(int index) ??? ??????? index??? ????? ??(??)??.
32
7. ?????? (5/7)
  • String ???
  • String ???? ???? ??? ???? ???? ?? StringBuffer
    ???? ???? ??? ?? ?? ? ??. ??? String ?????? ????
    ??????? ??.
  • String???? ??? ?? ??? ?????.

public char charAt(int index) ?????? index??? ?? ??? ??(??)??. public int indexOf(char char) ??????? char? ???? ??? ??? ??? ??? ???? ??(??)??. public int length() ?????? ??? ??(??)??. public String substring(int begin, int end) ??????? ??? ????? begin?? end?? ???? ????. ?? ??? ??? ????? end?? ???? end-1?? ????? ????. ?, ??? ??? ????? end???? ????. public String trim() ?????? ??? ???? ??? ?????. public String toLowerCase() ?????? ?? ???? ????. public String toUpperCase() ?????? ?? ???? ????.
33
7. ?????? (6/7)
  • StringBuffer ???
  • StringBuffer ????? ???? ?? ????? ??. StringBuffer
    ???? ???? ??? ??? String ?????? ???? ????? ????.
  • StringBuffer???? ??? ?????

public int capacity() ?? StringBuffer??? ??? ???? ??? ??(??)??. ???? ??? capacity()? ???? ????. public void ensureCapacity(int len) ?? StringBuffer??? ??? ???? ??? len?????? ????. public StringBuffer reverse() ?? StringBuffer??? ??? ????  ???? ????. ???? "abc"? ??? "cba"? ??. public StringBuffer append(Object o) ?? StringBuffer??? ??? ???? ?? ??? ??? ? ??. ?? Object, String, boolean , char, int ?? ??? ?? ? ? ??. public StringBuffer insert(int offset, String str) ?? StringBuffer??? ??? ???? ?? ???? ??? ??? ? ??. ?? ???? offset?, ???  ??? str? ??? ??. ?? String?? ?? ??? Object,  boolean , char, int ?? ??? ?? ? ? ??.
34
7. ?????? (7/7)
  • StringTokenizer ???
  • ???? ???? ?? StringTokenizer ???? ????.
    StringTokenizer ???? ???? ??(Token)?? ??? ??? ???
    ? ??. ??(Token)? ??? ???? ??? ???? ???. ??? ??
    ???(delimiter)? ???? ????. ?? ???(delimiter)?
    ??(,), ???(.), ??( )???? ??? ? ??.
  • StringTokenizer ???? ???

public StringTokenizer(String str, String delimiter) delimiter? ???? ??? ????. public StringTokenizer(String str, String delimiter, boolean returnDelims) delimiter? ???? ??? ?????  delimiter? ??? ??? ???? ? ??? ????. ??? ????? returnDelims? true? ????, ??? ????? ? ??? false? ???? ???.
Write a Comment
User Comments (0)
About PowerShow.com