Using Java to understand program logic error problems

Source: Internet
Author: User

This topic examines the definition and invocation of the Java parameter method. The parameters of a Java method can be any type, any number, the return value is unlimited, the returned type must be consistent, and the type of the formal parameter and argument must be the same.

So the correct answer to this question is D.

Analysis of test questions

The syntax for creating an object is: Class Name Object name =new class name (), so the correct answer is BD

A. The array subscript starts with "0" and remembers this.

B. The array element type must be the same, do homework when you know.

C. You'll know when you do your homework.

D. is length, without parentheses

The subject examines the understanding of the "= =" operator. "= =" is used to compare whether two objects are the same object, and if so, returns True, otherwise false. In new A () ==new a (), "= =" creates an object on either side of the "= =" with the new keyword, opening space in memory, respectively, to a different object, so the expression result is false. b should be selected.

The address of the instance object created by new does not match, so false

The book format is top-down, that is, from top to bottom, it may be a snap to see a as a top-down so choose the wrong.

Be sure to note that a is bottom-up not top-down! (The eye is tilted)

The while loop is first judged in execution, the loop condition is Num<5,num's initial value is 0, when NUM is 4 the time to execute +1, this time num is 5, end loop, num=5.

The continue statement functions to end this cycle and enter the next loop. When Num enters the next loop for 3 ahead of time, skip the code behind the loop body.

The correct answer is BC. In a method of a class, you can refer to other methods in the class directly using the method name, so B is wrong. When invoking a method defined by another class, if the method is a static method, you do not need to create an instance of the class first, so C is inaccurate.

Not all methods must have a method body (abstract methods do not require a method body), and all d is incorrect.

This topic examines the definition and invocation of the Java parameter method. The parameters of a Java method can be any type, any number, the return value is unlimited, the returned type must be consistent, and the type of the formal parameter and argument must be the same.

So the correct answer to this question is D.

The GetID method is private and cannot be accessed in other classes;
The local variable num was not initialized before the use of the assigned value;

This problem is more confused, at first it seems that the test is the basic type as a parameter to pass, but in fact, the test is the student's degree of care, because System.out.println () is printed in the Method1 return value, Method1 of course, the return value is num++, that is, 6.

The correct answer is C. This topic examines nested loops, outer i=0, Inner loop j=1,1<0 not established, not executed; outer I=1, inner loop still conditions are not established; outer i=2, Inner loop j=1,1<2 set up, loop once output 21, then J + +, condition not set, inner Loop end, meanwhile, The outer loop also ends.

This article examines static variables and static blocks, which are completed when the class is loaded, so the first static block X becomes 15 and then the second static block X becomes 5. Then execute main (), at which point the X has become 5 when the class is loaded. Note that static blocks are completed when the class is loaded, and multiple static blocks are executed in sequence. So the correct answer is C.

A total of 3 sequential, each cycle I value plus 2, when the end of the loop I value is 7.

Using Java to understand program logic error problems

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.