Short answer questions encountered in the interview -1

1. The difference between throws and throws

public Test() throws RepletException {
    try {
       System.out.println("Test this Project!")
    }catch (Exception e) {
      throw new Exception(e.toString());
    }
}

   Throws is used to declare all the exception information that a method may throw.
   Throw refers to a specific exception type thrown.
   Usually, the exception information that the method (class) may throw is declared through throws at the declaration of a method (class), and a specific exception information is declared through throws inside the method (class).
   throws usually does not need to capture exceptions displayed, and the system can automatically throw all captured exception information to the superior method;
   throw requires the user to capture the relevant exceptions, and then package them, and finally throw the wrapped exception information.

 

2. The difference between abstract (abstract class) and interface (interface)

    1. The abstract class represents an inheritance relationship in the Java language, and a class can only use the inheritance relationship once. However, a class can implement multiple interfaces.

    2. In the abstract class, you can have your own data members, or you can have non-abstarct member methods, while in the interface, you can only have static data members that cannot be modified (that is, they must be static final, but in the interface Generally do not define data members), all member methods are abstract.

    3. The subclass that inherits the abstract class must implement all the abstract methods of the abstract class, otherwise the subclass must also be an abstract class; the class that implements the interface must implement all the methods in it. Abstract classes can have non-abstract methods. Interfaces cannot have implementation methods.
    4. The variables defined in the interface are of public static final type by default, and their initial values ​​must be given, so the implementation class cannot redefine or change its value.
    6. Variables in abstract classes are of friendly type by default, and their values ​​can be redefined or reassigned in subclasses.
    7. The methods in the interface are of public, abstract type by default.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326957265&siteId=291194637