Java face question

Source: Internet
Author: User

1. Character Definition:

        Char c=65;        System.out.println (c);

Output Result:

A

Parsing: Defining character patterns in Java:

    • Direct definition character: Char c1= ' A ';
    • ASCII code corresponding to character: Char c2=65;
    • The byte definition range is -128~127

2, program output results

        int a = 5;        System.out.println ("Vlaue is" + ((a < 5)? 10.9:9));

Output Result:

Vlaue is 9.0

Conditional expression Execution Description:

    • The expression 1 is solved first, if the value is not 0, the condition is true, the expression 2 is solved, and the value of the expression 2 is the value of the entire conditional expression, and if the value of expression 1 is 0 and the condition is false, then the value of expression 3 is the value of the entire conditional expression.
    • Conditional expressions have precedence over the assignment operator only, and are lower than all operators that were previously encountered.
    • The binding direction of the conditional operator is "from right to left".
    • As long as there are different types in an operation, involving type conversions, the compiler will move down (the basic type ) and then perform the operation.
    • The last two expressions in the trinocular operation, one is a constant expression, the other is the T type, and the constant expression can be represented by the T type, then the output is the T type.

Analysis: Because there is a 10.9 in front, so 9 is automatically promoted to 9.0, so the final output is 9.0.

3, program output results

        char x = ' x ';         int i = ten;        System.out.println (false ?) i:x);        System.out.println (false ?) 10:X);

Output Result:

120
X

Analysis: int i=10; I is a variable, so the first output x is promoted to int type, ' X ' corresponds to a value of 120, so output 120; When the last two expressions in the trinocular operation are a constant expression (10 in the subject), the other is the T type (char in the case), and the constant expression can be represented by the T type, the output is the T type. Because 10 is a constant and can be represented as a char type, the output is char.

4. The following output results:

 Public class test1 {    privateint  count;      Public Static void Main (string[] args) {        //  TODO auto-generated method stub           New test1 (in);        System.out.println (T1.count);    }    Test1 (int  ballcount) {        = ballcount;    }}

Output Result:

99

Analysis: Count is defined as a private property and does not prevent the constructor from initializing it, but it is also possible to invoke a private property in the class, but not if it is not in the same class.

 Public class test1 {    publicstaticvoid  main (string[] args) {        new Test2 (n);        System.out.println (T2.count);    }} class test2 {    privateint  count2;    Test2 (int  ballcount) {        = ballcount;    }}

The code above compiles an error: The field Test2.count2 is not visible

Java face question

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.