Java common interview questions Share

Hello everyone, I'm here again! Today gave us a few common interview questions based on java, hoping to be helpful to you, oh. What problems can be directly issued a comment Oh, thank you for your support! 

 

1, static blocks and blocks are instantiated to perform at what time?

Static block is executed when the class is loaded, executed only once.

Examples of the block is executed upon generation of objects, each object is generated once, execution super () after.

 

2. What is the inner class? What inner class class files named?

In a further class defines a class called inner classes. Internal class corresponding to the outer class attributes, generating an internal class object must rely on external object.

Naming inner class class files: external internal class name class name $ .class

 

3. What is polymorphism? Polymorphic What are the characteristics?

Polymorphism refers to allow the use of the parent class reference variable subclass object, allowing the use of a variable reference to the interface implementation class objects, but not vice versa.

Polymorphic features: the same behavior, different implementations.

 

 

4, what is the abstract class? What is an abstract method?

If only the definition of a method, there is no specific content, called an abstract method, modified by abstract.

With abstract modification, and allows the abstract methods defined in the class is an abstract class called class.

 

5, how to define the interface? Implement an interface with what keywords? What a class that implements the interface must be done?

Definition of the interface: interface

Implement an interface: implements

A class implements an interface, all the abstract methods defined in the interface needs to be rewritten, otherwise it can only be a kind of abstract class

 

 

6, what methods defined in the interface modifier is? What variables defined in the interface modifier that?

A method as defined in the interface modifier: public abstract

Variable is defined in the interface modifiers: public static final

 

7. What is abnormal? Error and Exception What is the difference?

The exception is the error message describing the object.

Throwable is the parent class has two subclasses: Error and Exception.

Error represents the collapse of the level of error, developers can capture, but can not handle.

Exception represents the general level of error, developers can capture, can handle.

 

8, how abnormal the execution order? If you have a return in the try block, finally will be implemented?

First the try block, the order of execution, if the occurrence of abnormality to execute the catch block, at the same time suspended rest of the code in the try block. Whether or not there is an exception, the finally block will be executed.

If there is a return statement in the try block or catch block, finally out before the method is executed.

 

9. What is the difference between throw and throws?

throw is a statement, expressed explicitly thrown objects. throw new Exception ();

It throws a method modifier indicates that the method may throw some kind of exception. When calling this method, you need to deal with this method throws an exception.

 

10, abnormal divided into several? How to differentiate?

Disorders fall into abnormal compile (abnormalities) and runtime exception (unchecked exception).

Which compile an exception, it requires developers to have to deal with. If not addressed, will not compile.

Runtime exception, developers can handle, do not deal with. If untreated, it can compile.

All runtime exception is a subclass of RuntimeException.

 

The next issue I will give you the knowledge to talk about Java polymorphism, there is a need friends can see Oh

 

 

 

Guess you like

Origin www.cnblogs.com/lyslyslyslyslys/p/12001475.html