Scjp review notes (2)

Source: Internet
Author: User

 

Example 11:

Note the usage of length and length (): for example, string STR = "My name is wuyangping" is used to evaluate the length to Str. length (); but string [] STR = new string [5], the length of this is str. length.

Example 12:

The output input format in Java is also supported. For example, system. Out. printf ("Pi is approximately % F and E is approximately % B", math. Pi, math. E );

The output result is: PI is approximately 3.141593 and E is approximately true.

Example 12:

Public class beat {

Integer I; // Line 2

Int X;

Public beat (INT y ){

X = I + Y; // line 5

System. out. println (x );

}

Public static void main (String [] args ){

New Beat (new Integer (4); // line 9

}

}

NullPointException exception occurs during I compilation in Line 2. Change it to Integer I = new Integer (1.

Example 13:

This introduces the object-oriented design. From Chapter 1, the difficulty was quickly increased, and the number of questions in each chapter began to increase. When encountering an inherited or multi-type question, be sure:

Step 01: roughly draw a category Chart Based on the program.

Step 02: Check whether the parent category provides a parameter-free constructor. If no parameter constructor exists, the subcategory should

Call super (Hangzhou) or this (...) in the second line of the constructor (...). If no super (callback) or

This (...) should cause compilation to fail!

Step 03: Check whether the overwriting method meets the rules (see section 9-4: overwriting method).

Step 04: Check whether multiple types are used (variables or parameters declared with upper-layer types are used to refer to lower-layer types

Object created ). If multiple models are used, pay attention to whether the called method covers the quilt category.

Step 05: if there is a transformation in the program, check whether there will be execution errors.

In this way, the problem solving or inspection program should be able to obtain results.

Example 14:
The naming rules for JavaBean are setXXX (), getXXX (), and isXXX ();

Example 15:

Class Foo {

Public int a = 3;

Public void addFive () {a + = 5; System. out. print ("f ");}

}

Class Bar extends Foo {

Public int a = 8;

Public void addFive () {this. a + = 5; System. out. print ("B ");}

}

Public class Person {

Public static void main (string d []) {

Foo F = new bar ();

F. addfive ();

System. Out. println (F. );

}

}

The output is B 3. F. A calls the method of the parent class.

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.