Encapsulating and inheriting jobs

< p align = "center" > encapsulate and inherit jobs

1、 Multiple choice questions

Change private int m to protected int m

Base(a,b);

static A

static B

I'm A class

HelloA

I'm B class

HelloB

2、 Judgment question

Access modifier: it can modify variables, methods and classes

Modifier variable: all four modifiers can be used

Modification method: all four modifiers can be used

Decoration class: 2 kinds of public, default

(1) method overloading: exists in a class

Method names must be the same

Different parameter lists (different number, type and order of parameters)

Independent of return value

(2) Method Rewriting: it exists in the child parent class, and the child class rewrites the method of the parent class

The return value, method name and parameter list must be consistent

The access modifier of the subclass must be greater than or equal to the access modifier of the parent class

Object class has a default constructor pubilcobject (), which will be called first when constructing subclass instances.

Equals () method: used to test whether an object is equal to another object. Its implementation in the object class is to judge whether two objects point to the same memory area.

Tostring(): returns the string representation of the object. The toString () method in the object class prints out the class name and the memory location of the object. Almost every class overrides this method to print a representation of the current state of the object.

f    inalize

    protected void finalize()

     throws Throwable

This method is called by the object's garbage collector when the garbage collector determines that there are no more references to the object. Subclasses override the finalize method to configure system resources or perform other cleanup.

    wait

    public final void wait()

throws InterruptedException

Causes the current thread to wait until another thread calls the notify() method or notifyall() method of this object. In other words, this method behaves as if it only performs a wait (0) call.

    notify

    public final void notify()

Wake up a single thread waiting on this object monitor. If all threads are waiting on this object, one of them will be selected to wake up. The choice is arbitrary and occurs when a decision is made about the implementation. The thread waits on the object's monitor by calling one of the wait methods.

1. The construction method of its base class must be called during the construction of subclasses.

2. Subclasses can use super (argument_list) in their own constructor to call the constructor of the base class

2.1. Use this (argument_list) to call another constructor of this class.

2.2. If super is called, it must be written in the first line of the subclass construction method.

3. If the constructor of the base class is not shown in the constructor of the subclass, the system will call the parameterless constructor of the base class by default.

4. If it is not shown in the subclass construction method to call the base class construction method, and the base class does not have a parameterless construction method, there is a compilation error.

The super subclass can call the method of the parent class through it, which is written in the first line of the construction method

    1. Basic data type

Also called raw data type. For the comparison between byte, short, char, int, long, float, double and Boolean, the double equal sign (= =) is applied to compare their values.

    2. Composite data type (class)

When they use (= =) when comparing, the storage address in memory is compared. Therefore, unless it is the same new object, the comparison result is true, otherwise the comparison result is false. All classes in Java inherit from the base class object, and an equals method is defined in the base class in object. The initial behavior of this method is Compared with the memory address of the object, but this method is overwritten in some class libraries, such as string, integer and date. Among these classes, equals has its own implementation, rather than the storage address of the comparison class in heap memory.

For the equals comparison between composite data types, without overwriting the equals method, the comparison between them is still based on the address value of their storage location in memory, because the equals method of object is also compared with the double equal sign (= =), and the result after comparison is the same as that of the double equal sign (= =).

4、 Coding question

requirement:

1) set the private access permission of the attribute, and access the attribute through the public get and set methods

2) it employees must be at least 15 years old, invalid information needs to be prompted, and the default age is 15.

3) define "technology direction" as a read-only attribute

4) work method: receive the work unit and job through input parameters, and output personal work information

5) write test classes to test the objects and related methods of IT Practitioners (test data information customization)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>