Java base face 28 questions - on

Imperial College [soft] 28 basis java face questions
1, object-oriented features have what?
A: The object-oriented features mainly in the following aspects:
Abstract: Abstract is summed up a common feature of the process of constructing a class object class, including data abstraction and abstract behavior in two ways. Only concerned with abstract objects which have attributes and behaviors, not concerned about the details of what these behaviors yes.
Inheritance: Inheritance is the process of creating a new class of information to be inherited from an existing class. Provide information inherited class is called the parent class (superclass, base class); information be inherited class is called a subclass (derived classes). Inheritance allows a software system changes in a certain continuity, while inheriting an important means of variable factors also package the program (if not understand, please read "Java and model," or "design patterns refined solution" Yan Hongbo disabilities regarding part of the bridge mode).
Package: Encapsulation is generally considered a method of operating data and bind data, access to the data only via the defined interfaces. Object-oriented nature of the real world is portrayed as a series of fully autonomous, closed objects. Our method is written in a class implementation details of a packaging; we write a class that encapsulates the data and operations. We can say that the package is to hide all hide things, provide only the most simple programming interface to the outside world
Polymorphism: polymorphism refers to allow objects of different sub-types respond differently to the same message. Simply put, it is to call the same method but do different things with the same object reference. Polymorphism Polymorphism Polymorphism is divided into compile-time and run when. If the method of the object viewed as an object to provide service to the outside world, then the run-time polymorphism can be interpreted as: When A system to access services provided by the system B, B system has a variety of ways to provide services, but all of A systems are transparent (as if the electric shaver is a system which is the system power supply system B, system B can be used with AC or battery-powered, they may even be solar, it will only be passed class B a power supply object calls methods, but did not know the underlying supply system to achieve what is, exactly how gained momentum through). Method overloading (overload) is implemented compile-time polymorphism (also called pre-binding), and method overrides (override) to achieve polymorphism (also called a binding post) runtime. Run-time polymorphism is the essence of an object-oriented best thing to achieve polymorphism need to do two things: 1) method overrides (subclass inherits the parent class and the parent class has or abstract method overrides);. 2) object modeling (referenced by the parent type reference subtype object, so the same reference to the same method call will exhibit different behavior depending on the subclass objects).

2, String is the most basic data type?
Answer: It is not. The basic data type in Java only 8: byte, short, int, long , float, double, char, boolean; in addition to the basic types (primitive type) and enumerated types (enumeration type), and the rest are reference types ( reference type).

4, float f = 3.4; correct?
Answer: Incorrect. 3.4 is a double precision number, the double (double) assigned to the floating-point (float) belonging to the next transition (down-casting, also referred to as narrowing) will cause loss of precision, it is necessary cast float f = (float ) 3.4; or written float f = 3.4F ;.

5, int and Integer What is the difference?
A: Java is a nearly pure object-oriented programming language, but in order to facilitate the programming or the introduction of the basic data types, but in order to be able to these basic data types as object operation, Java for each elementary data types introduced corresponding wrapper type (wrapper class), int wrapper class is Integer, since Java 5 introduced automatic boxing / unboxing mechanism, so that the two can be interchangeable.
Java provides a package type for each primitive type:

Original Type: boolbean, char, byte, short , int, long, float, double
Package Type: Boolean, Character, Byte, Short, Integer, Long, Float, Double
6, explanation of the memory stack (stack), Heap (heap ) and the use of a static area (static area) of
a: usually we define a basic data types of variables, a reference to an object, there is on-site use function calls to save stack space in memory; and through the new keyword and construction objects created in the heap; literal (literal) program, such as direct-write 100, "hello" and constants are placed in the static area. Stack space to operate the fastest but the stack is very small, usually a large number of objects are on the heap space, in theory, the entire memory space is not being used by other processes and even virtual memory on the hard disk space can be used as piles.

String str = new String ( "hello ");
The above statement str variable on the stack, create it with the new string object on the heap, and "hello" in the literal static area.

Added: Newer versions of Java (starting from a Java update 6) used a called "escape analysis" technology, a number of local objects can be placed on the stack in order to improve the operational performance of the object.

7, Math.round (11.5) is equal to how much? Math.round (-11.5) equals how much?
A: Math.round (11.5) return value is 12, Math.round (-11.5) returns the value -11. Rounding principle is applied on the parameter and then 0.5 under rounding.

8, the array has no length () method? String has no length () method?
A: Arrays are not length () method, length attributes. String has a length () method. JavaScript, the length of the string was obtained by the length property, which is easily confused and Java.

9, the constructor (constructor) can be rewritten if (override)?
A: The constructor can not be inherited, and therefore can not be rewritten, but can be overloaded.

10, can inherit String class?
A: String class is final class can not be inherited.

11, the difference between overloading (Overload) and rewritable (Override) is. Overloaded method can be differentiated according to the type of return?
A: rewriting method overloading and are multi-state manner, except that it is implemented compile-time polymorphism, which polymorphism is achieved runtime. Overload occurs in a class, the method of the same name if there are different list of parameters (parameters of different types and different number of parameters or both) is considered overloaded; rewrite occurs between the child and parent class, subclasses override the requirement is overridden method with the parent class is overridden method with the same return type, method is overridden better access than the parent, can not be overridden method declares more exceptions (Richter Deby parent change principle). Overloaded no special requirements for the return type.

12, abstract class (abstract class) and interfaces (interface) What are the similarities and differences?
A: no abstract classes and interfaces can be instantiated, but the reference may be defined type of abstract classes and interfaces. If a class inherits an abstract class or implements an interface need to abstract methods to achieve all of them, otherwise the class still need to be declared as an abstract class. Interface more abstract than the abstract class, can be defined as an abstract class constructor can have abstract methods and specific methods, but can not define the interface and wherein the constructor methods are all abstract methods. Abstract class members can be private, default, protected, public, and interface are all members of the public. You can define an abstract class member variables, and member variables defined in the interface actually are constants. There are abstract methods of the class must be declared as an abstract class, abstract class may not have abstract methods.

13, String s = new String ( "xyz"); created several String Object?
A: The two objects, a static area of "xyz", with a new one is created in the object on the heap.

14, Java's final keyword in what usage?
A: (1) modifying classes: the class can not be inherited representation; (2) modification methods: Method representation can not be rewritten; (3) modification of variables: variables can only represent an assignment can not be modified after the (constant).

Comments may be interested contact me Oh brother! Trained, trained, trained,

Guess you like

Origin blog.51cto.com/14623707/2458496