2019/07/10 preparation of java

Plan:

  • Check the title in the morning, then back again to check yourself over more than
  • At noon there is time to review the main back again yesterday
  • Evening back again the next day at noon and a
  • Read through the fourth day between classes
  • Read through the seventh day recess
  • Read through the fifteenth day between classes

Contact and the difference between interfaces and abstract classes.
The difference between the grammatical level
1) A class can inherit an abstract class, but a class can implement multiple interfaces;

Member variable 2) interface is only public static final type (constant); abstract class member variable can be of various types

3) an interface not contain any non-abstract methods, abstract classes can (beginning from jdk8 interface can have default method)
4) The method can interface is public. Abstract methods abstract class may be public, protected, default type
5) the interface can not contain a static block and a static method, a static abstract class can have static methods and code blocks;

6) multiple inheritance and the interface between the interface, the extends public interface A B, C
. 7) an interface can inherit an interface; An abstract class can implement the interface, the abstract class can inherit an abstract class.

8) the interface is not a constructor, but can not be instantiated. Abstract class has a constructor, not be instantiated.
Difference in the design level
1) abstract class is an abstraction of a thing, that is an abstract class, and the interface is an abstract behavior. Abstract class is an abstract class for the entire whole, including attributes, behavior, but the interface is based on the partial (behavior) abstract.
Inheritance is an "is not" relationship, while the interface is "there is no" relationship.
Different 2) the design level, abstract class as many sub-class of the parent class, it is a template design. The interface is a code of conduct, it is a radiant design.
3) To modify the properties generally only used when the parent class abstract class, try to use the interface.


and finalize the difference between final and finally the
front. 1, may be used for final keyword class, method, variable. Keyword is used to indicate that the modified classes, methods, variables having immutable characteristic.

 1.final关键字用于基本数据类型前:这时表明该关键字修饰的变量是一个常量,在定义后该变量的值就不能被修改。
 2.final关键字用于方法声明前:这时意味着该方法时最终方法,只能被调用,不能被重写,但是可以被重载。
 3.final关键字用于类名前:此时该类被称为最终类,该类不能被其他类继承。

2, finally finally block to provide exception handling to perform any cleanup. Whether or not an exception is thrown, caught, finally block will be executed.

try块中的内容是在无异常时执行到结束。
catch块中的内容,是在try块内容发生catch所声明的异常时,跳转到catch块中执行。
finally块则是无论异常是否发生,都会执行finally块的内容。

So there is a need in the code logic, no matter what the code that must be executed occurs, it can be placed in the finally block.

3, finalize is the method name. java technology allows the use of finalize () method to remove the object to do the necessary clean-up work before going out from memory in the garbage collector.

This method is determined by the garbage collector in this object is not called when this object is referenced.

It is defined in the object class, so all classes inherit it. A subclass overrides the finalize () method to organize system resources or perform other cleanup work is.

finalize () method is to delete the object before the garbage collector calls this object . Manually call System.gc () to mobilize the garbage collector can call this method machine



Types and characteristics within the class.
Inner classes can be divided into many kinds, but there are four kinds of inner classes: static inner classes, members of inner classes, local inner classes, anonymous inner classes.

1. static inner class refers to an inner class declared as static can not be accessed outside the class of ordinary member variables can only be accessed outside the class static member variables and static methods.

2. Remove the keyword static inner classes is a member, you are free to reference the properties and methods of the outer class.

3. Local inner class definition refers to a class code block, code block where its scope.

局部类类似于局部变量一样,不能被public、protected、private以及static修饰,
只能访问方法中定义为final类型的局部变量。

4. anonymous inner class is a class with no internal class name, do not use the keyword class, extends, implements, it must inherit from other classes or implement other interfaces.

(1) anonymous inner classes can not have a constructor

(2) can not define static members, methods and classes

(3) can not be public, protected, private, static.

(4) can only create an instance of an anonymous inner class

interface Person {
    public void eat();
}

public class Demo {
    public static void main(String[] args) {
    //new person后面大括号里的就是匿名内部类
        Person p = new Person() {
            public void eat() {
                System.out.println("eat something");
            }
        };
        p.eat();
    }
}

Guess you like

Origin blog.csdn.net/vcviql/article/details/95299234