美文网首页
Java 考试复习

Java 考试复习

作者: SetsunaChiya | 来源:发表于2016-11-16 22:40 被阅读0次

    package packagename;

    1.可以使用类的全称,例如:使用javax.swing.JOptionPane来调用JOptionPane
    2.import类,之后可以使用类的简称
    import的类在编译或运行时都不会读取,除非这个类在程序中用到了。
    import语句仅仅告诉编译器去哪里找这个类。

    数组
    定义:datatype[] arrayRefVar;datatype arrayRefVar[];(不提倡)
    例:int[] a;int a[];

    创建:arrayRefVar = new datatype[arraySize];
    例:a = new int[10];

    定义并创建:datatype[ ] arrayRefVar = new datatype[arraySize];
    例:int[] a = new int[10];

    定义、创建并初始化:
    例:int[] a = {1,2,3};

    // Declare array ref var
    dataType[ ][ ] refVar;
    // Create array and assign its reference to variable
    refVar = new dataType[10][10];
    // Combine declaration and creation in one statement
    dataType[ ][ ] refVar = new dataType[10][10];
    
    int[ ][ ] array = {{1, 2, 3},{4, 5, 6},{7, 8, 9},{10, 11, 12}};
    

    参差数组Ragged Array

    int[ ][ ] array = {{1, 2, 3},{4, 5},{6}};
    

    传参方式
    pass by value:跟C/C++一样,基础数据类型传行参,数组之类的传实参

    返回类型
    数组 int[]

    Object类型

    面向对象


    java里把成员变量和成员函数叫做数据域Data Field和方法Method

    默认值
    The default value of a data field is
    – null for a reference type,

    – 0 for a numeric type,

    – false for a boolean type

    – '\u0000' for a char type

    作为对比,一个方法里的本地变量是没有默认值的。

    private修饰的数据域/方法限制在类内
    默认的数据域/方法限制在包内
    public修饰的数据域/方法无限制

    可变mutable/不可变immutable
    实现数据域的不可变:以private修饰,不提供mutator方法,不提供会返回该数据域的引用的方法

    实例变量、方法:Instance Variables, and Methods
    类变量、方法

    继承

    this->相当于Python里的self.
    继承的语法public class Cylinder extends Circle {

    构造函数:
    子类不会继承父类的构造函数
    子类的构造函数第一句都是super(不写编译器会给加上super())
    super关键字用来调用父类的构造函数
    super()
    在子类中调用父类构造函数会出Syntax Error

    toString()override

    If a method’s parameter type is asuperclass (e.g., Object), you may passan object to this method of any of theparameter’s subclasses

    instanceof

    Paste_Image.png

    For example, if a method is defined as public in thesuperclass, it must be defined as public in thesubclass.

    Initialization blocks

    Paste_Image.png
    Chapter 9: Objects and Classes
    
    static {System.out.println("A's static initialization block " +
     "is invoked"); }
    

    垃圾回收(GC,Garbage Collection)
    自动的

    相关文章

      网友评论

          本文标题:Java 考试复习

          本文链接:https://www.haomeiwen.com/subject/cuzrpttx.html