Java does not face questions wrong or summary

1. The eight basic data category and type of package size (bytes)

答:byte Byte 1

short Short 2

int Integer 4

long Long 8

float Float 4

double Double 8

char Character 2

boolean Boolean - (boolean JVM is not the type of data, based on "Java Virtual Machine Specification", boolean will be compiled into JVM int data type instead, boolean arrays will be compiled into JVM byte array, boolean each accounted for 8, Therefore boolean alone accounted for 4 bytes, but with the array of boolean boolean each 1-byte)

That JVM Why use int instead of boolean it, more than a byte or short to save memory space? In fact, with the reason for the current int 32-bit CPU, (here 32/64 bit system, but rather refers to the hardware level CPU), having the characteristics of high access

 

2. This question wrong, the correct answer posted understanding out

. 1          // int y = x ++ + ++ x; x ++ 4 first, and then to complete this step becomes 5, and then ++ x 6, so 10 y
 2          // if int y = ++ x + x ++; results of 10, but the process is not the same: first ++ x is 5, then x ++ is also 5 
. 3          int X =. 4 ;
 . 4          int Y = x ++ + ++ x; // Y =. 4 +. 6 = 10, Finally, the value of x. 6 
. 5          System.out.println (x + Y + ++ x ++); // . 7 + + 10 = 24. 7, 24 is so printed

 

3. The difference between == and the equals

i. General == comparison with basic data types, equals comparison with

. Ii == Analyzing two variables or examples are not directed to the same memory space, the memory address is compared; the determination value equals two variables or instance of that memory space is the same

iii. == it is simply determines whether the same reference, equals the same value is determined

 

X 4. A class has a method, class B inherits class A, class B x method of access modifiers (private, public these) change it? How to change?

A: The only change in the direction of a more visible, for example, x Method A class is protected modified, x B class methods that can only be public, because the parent class method to avoid visible and not visible to the subclass

 

5. A class has a method x throw out an exception, class B inherits Class A and x overrides the method, ask what you want to throw an exception?

A: The only throw down, i.e. A throw exception subclass of class x methods, such as x Exception throw method A, method B throw InterruptedException. This is because the compiler requires a call to the subclass method of capture is abnormal when the parent class method, so if x Method B throw exception is abnormal A parent, it can not catch exceptions A method of the x

 

Modifiers difference 6. public, protected, default, private access to these

A: public: "Public" and all of its modified class, all class attributes and methods can be accessed (similar, with different packet classes, subclasses different packages, different packages of non-child class)

protected: "protected form", it modifies the classes, properties and methods may be (grade, with different packet classes, subclasses different package) access, can not be (non-child classes of different packages) Access

default: "default access mode" which modified classes, attributes and methods may be (grade, with different types of package) access, can not be (subclasses of different packages, the packages of different non-child class) Access

private: "private", it modifies classes, properties and methods can only be accessed by objects of this class, other classes to access private property to use getter, setter methods

 

7. initialization sequence (the title he was given the code, class B inherits class A, then the two main methods in the new class B, ask what will print)

A: The parent class static properties (called once only)> parent class static block of code (called once only)> subclass static properties (called once only)> subclass static block of code (called once only)

> Parent class code block non-static> parent class constructor> subclass block non-static> subclass constructor

 

 

Firstly written on October 16th, 2019

Why use that virtual machine instead of boolean int it? Why not byte or short, so do not save more memory space. Most people will naturally think of this, I also have this question, through access to information that, use int reason is that for the moment the 32-bit processor (CPU), the data processing time is 32 (not here refers to a 32/64 bit system, but rather refers to the hardware level CPU), having the characteristics of efficient access.

Guess you like

Origin www.cnblogs.com/LittleMike/p/11689003.html