Object-oriented interfaces 20 Notes

Recalling
? 1. The root class of all classes is what we need to do?
Object
override methods: ***** toString (), *** equals () & hashCode (), finalize ()

2. When we do not wish to be inherited class, the public final class how to do the final class, sealed class
when we do not want to approach overridden by subclasses, how do public final return type name () {}

3. The virtual methods and similarities and differences Abstract

4. The abstract method can be declared as final do?
Can not, abstract must be achieved through inheritance and rewriting
final: can not rewrite the
contrary,

Abstract method can be declared as static it?
Not possible
reasons:
(1) abstract method is the way to go subclass declaration, requires that the perpetrator subclass,
a static he does not need to inherit, but does not require the object
is created when the class has been completed code segment
(2) for the sub-category in terms of static, is directly used, it will go directly to inherit a fully functioning site
construction methods can be static it?
No, static and unrelated objects

Course content - Interface
1. What is the interface
2. How to declare an interface
3. Interface
3.1 using our own interface
3.2 uses the Java API to click of a button

Interface inheritance 4.
5. Interface Specification
6. common interface

1. What is the interface?
1.1 functions:
1. constraint function implementation class
2. Java single inheritance make up less than
1.2 interface is the difference between type, and a reference to the class that
the interface is not the type of restrictions, does not focus on race relations, focusing on behavior
inheritance: animals: cats, dogs, frogs, birds
interfaces relations: a focus on function: birds and aircraft have in common (same functionality)
name: verb + able:
reference types: arrays, classes, interfaces
1.3 a class multiple interfaces
1.4 features:
. a new interface is not an object
. method B interface are abstract, but no need to write the abstract
c interface attribute is a static constant, can not be modified.
D class that implements the interface must be rewritten. All the abstract methods, if not possible,
then this class as an abstract class

2. How to declare an interface
public interface interface name {
// attributes
// methods
}

3. How to implement the interface
public class xxx extends a parent class implements an interface, the interface 2 {

}

LSP 3.1
Collectable c = new new Teacher ( "Chen", 30, Person.FEMALE, "JavaSe ", 5,10000);
compile-time type Collectable
direct calls is declared in the Collectable: SPEED, collectHomeWork
runtime type Teacher
actually c contains the Person class declaration method and method declarations Teacher

3.2 instanceof

Published 19 original articles · won praise 0 · Views 111

Guess you like

Origin blog.csdn.net/qq_45212924/article/details/105015784