Java face question and answer (i)

Source: Internet
Author: User
Tags finally block modifier

Final, finally, finalize differences

Final
A decorated class cannot have child classes
Modification methods cannot be overridden
Modifier variables cannot change values and must be initialized
Finally
The finally block will be executed regardless of whether an exception is caught or thrown when exception handling
Code that must be executed, regardless of what happens, is placed in the finally block
Finalize
Method Name, Java allows this method to do the necessary cleanup before the garbage collector clears the object from memory
Defined in object, all classes inherit from him, and subclasses override the Finalize () method to organize system resources or perform other cleanup work

int, Integer difference

Int
Basic data types
Initial value 0
No instantiation required
Storing data values directly
Integer
Packing class for int
Initial value NULL
Instantiation to use
A reference to the object, pointing to the new integer object

Differences between method overloads and method overrides
Method overloading
A method with the same name within a class
Parameter return value throws an exception that can be different
The same method handles different parameter lists (static polymorphism) according to the different input data
Method overrides
Subclasses override parent class methods with different implementations of the same parameters (dynamic polymorphism)
Method Name parameter return type consistent
Method modifies a modifier that is greater than the parent class
A new exception cannot be present, a broad exception than the parent class
Super () Call method of parent class
The final method cannot be overridden
The abstract method must override the

The difference between an abstract class and an interface
Abstract class
You can have your own implementation.
Can write the Main method
Cannot be instantiated
Subclasses inherit abstract classes through extends
can have constructors
Abstract methods can be modified by public protected default
You can inherit a class that implements multiple interfaces
Faster than interface speed
Abstract class adds a new method that provides a default implementation and does not need to be changed by another class
Interface
You can't have your own implementation.
You cannot write the Main method
Implementing the methods in the interface through implements must all be implemented
Cannot have a constructor
be modified by public
can inherit multiple interfaces
It's a bit slow, and it takes time to find out.
Adding a new method must provide a new implementation

Java face question and answer (i)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.