Java Foundation Pen Questions

Source: Internet
Author: User

Java Basics Pen Questions

Written test purpose : Exercise everyone's written ability, will not let you in the written test in the case of the forgotten words appear. At the same time, it is also a test of their own learning results, mastering the core of the most elite knowledge points.

    1. Question: What is object-oriented? (10 points)

This topic: Detection of object-oriented concepts, object-oriented characteristics of the understanding

Answer:

Object-oriented is a kind of programming idea. In the process of using the object, do not need to go inside how to implement the object, just need to know what can be achieved. (3 points)object-oriented with encapsulation, inheritance, polymorphism (3 points). Encapsulation concealed the details of the object without exposing, so that the internal details of the change with the outside world, relying only on the interface to communicate. Encapsulation reduces the complexity of programming. Inheritance makes it easy to create a new class, and a class gives the compiler a tedious task of getting its non-private methods and common properties from derived classes. The inheritance and implementation of the interface and runtime type binding mechanism produced by the polymorphic, so that the different classes produced by the object can be different response to the same message, greatly improving the generality of the Code (4 points).

    1. Problem: What is the difference between scope public,private,protected and not writing? (10 points)

This topic: detection modifiers and scope understanding.

Answer: The difference is as follows:

Scope Current class same package descendant class other package

Public√√√√ (2 min)

Protected√√√x (2 min)

Default√√xx (2 min)

Private√xxx (2 min)

Default when not written (2 points)

    1. Question: A brief description of final usage ? (10 points) ·

This topic: the understanding and use of final detection

Answer:

The final decorated class (1) cannot be inherited (2).

Final modifier attribute (1), value cannot be changed (2).

The final modification method (1) cannot be overridden (2).

Local variables are called in the methods of the anonymous inner class, and local variables need to be final decorated. (1)

    1. Problem: When an object is passed as a parameter to a method, this method can change the properties of the object and return the changed result, whether it is a value pass or a reference pass. (10 points)

This topic: The difference between detection value passing and reference passing

Answer:

is a value pass(4). Java programming language only values pass parameters(3)。 When an object instance is passed as a parameter to a method, the value of the parameter is a reference to the object. The contents of the object can be changed in the called method, but the object's reference is never changed(3).
    1. Question: briefly describe the use of static. (10 points)

This topic: Detection of static understanding and use

Answer:

Static decorated properties and methods, loaded with the load of the class, take precedence over the existence of the object. (3) shared by all objects, either through a class call or through an object invocation. (3)static modified method to access only static decorated members. (2)static keyword cannot and this,Super Simultaneous use. (2)

    1. Questions: The difference between overload and Overrid. Whether the overloaded method can change the type of the return value (10 points)

This topic: testing for Understanding of Overload and Overrid

Answer:

The overridden overriding and overloaded overloading of a method are different manifestations of Java polymorphism. (2) overriding overriding is a representation of polymorphism between a parent class and a subclass,(1) overloading Overloading is a representation of polymorphism in a class. (1) If a method is defined in a subclass that has the same name and argument as its parent, we say that the method is overridden (overriding). When an object of a subclass uses this method, the definition in the subclass is called, and for it the definition in the parent class is "masked". (3) If more than one method with the same name is defined in a class, they either have a different number of arguments or have different parameter types, which is called a method overload (overloading). The overloaded method is to change the type of the return value. (3)

    1. Questions: What is the difference between string and StringBuffer? (10 points)

This topic: Detection of the mastery of string processing

Answer:

The length of the String is immutable (3), andthe length of the StringBuffer is Variable (3). If you are frequently manipulating the contents of a string, especially if the content is to be modified, use stringbuffer(2)and, if a string is required at the end,use the StringBuffer of the toString () Method (2).

    1. Question: What is the area of "= =" and the equals method? (10 points)

This topic: understanding of "= =" and equals

Answer:

The = = operator is specifically used to compare the values of two variables for equality, that is, the values stored in the memory used to compare variables are the same. (4)

The Equals method is used to compare the contents of two separate objects, as compared to two people whose looks are the same, compared to the two objects that are independent of each other. (4)

For example, for the following code:

String A=new string ("foo");

String B=new string ("foo");

Two new statements create two objects, and then use a, B, to point to one of the two variables, which is two different objects, their first address is different, that is, the values stored in a and B are not the same, so the expression a==b will return false, and the contents of the two objects are the same. Therefore, the expression a.equals (b) returns True. (2)

    1. Question: can the constructor constructor be override? can abstract be modified at the same time as final? (ten)

This topic: Testing the understanding of override

Answer:

ConstructorsConstructorcan'tBerewriteoverriding(2),Constructor constructorcannot be inherited, soCannot be rewritten,but can be weighedOverloading(3).  Abstract does notcan andFinalSimultaneous modification Method(2), becauseAbstractthe modified method needs to be rewrittenoverrifing, whileFinalthe modified method cannot be overridden(3).

    1. Question: What is polymorphism. (10 points)

This topic: Detection for polymorphic understanding

Answer:

What we usually call polymorphism refers to the polymorphism of the object. (1) This means that the object has a variety of mentality. the type at compile time is determined by the type used when declaring the variable , and the type of the runtime is determined by the object that is actually assigned to the variable. If the compile-time type differs from the run-time type, polymorphism occurs. (2)

inheritance is a precondition for polymorphic generation . (1)

The mechanism for implementing polymorphism: The reference variable of the parent class can point to the instance object of the subclass, and the method called by the program is dynamically bound at run time, that is, the method that refers to the real instance object that the variable points to, that is, the method of the object that is running in memory, not the method defined in the reference variable's type (3)

polymorphic role: The different sub-class objects are considered as the parent class, you can block the differences between the different sub-class objects, write generic code, make general programming to adapt to the changing needs. (3)

Java Foundation Pen Questions

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.