当前位置:网站首页>Day_ twelve
Day_ twelve
2022-06-25 16:25:00 【grp_ grp_ grp】
Day12 object-oriented
1.Final
final For the embellishment , Indicates final , Unalterable
final The decorated class cannot be inherited , Decorated member methods cannot be overridden , Decorated variables cannot be assigned twice , And there is no default value
final Declaration of static variables :
public static final data type Variable name = value ;

2. polymorphic
Definition :
Parent class reference Point to Subclass object
Parent class reference : refer to A type variable declared with a parent type
Point to : It refers to which object can be found through the memory address
Subclass object : new Heap memory object created by subclass
Statement :
Parent type Variable name = new Subclass ();

Advantages of polymorphism : Embrace variety , Reduce the coupling between classes and details
The disadvantages of polymorphism : Missing subclass specific properties
call :
1 If the parent class doesn't have , Direct error
2 If the parent class has , Subclasses don't have , Execute parent
3 If both parent and child classes have , Member method execution subclass , Other execution parent classes

form :
1 Direct polymorphism
2 Formal parameters and actual parameters , The method parameter list is the parent type , Call methods to pass in subclass objects
3 The return value is polymorphic , The return value type is the parent type , But return subclass objects
instanceof
Determine whether an object is instantiated from a class

3. abstract
What is it? :
It's a modifier , The decorated class is an abstract class , The decorated method is abstract method
abstract class : Object cannot be instantiated
Abstract method : There is no method body , Define only the functions , No functional implementation , And the abstract method must be in the abstract class , But there can be no abstract methods in an abstract class

4. Interface interface
Interface : It can be understood as a completely abstract class , Class contains only abstract methods and constants
1.8 Start allowing Static methods and default methods
grammar : Modifier interface The interface name {}
Abstract methods in interfaces , No need to add abstract modification , Method The default is public abstract
Interface , No variables , Constant only , also public static final It can be omitted
Between classes and interfaces , No longer an inheritance relationship , It becomes an implementation relationship , from extends Instead of implements
The interface name Variable = new Subclass implementation () Polymorphism also occurs
One class Only one class can be inherited , however Can achieve N Interface , Separated by commas , It can solve the problem of weak single inheritance function
class Class name implements Interface 1 , Interface 2, Interface 3....{}
Interface and interface , It's multi inheritance , Separated by commas
interface The interface name extends Parent interface name 1, Parent interface name 2,...{}
One class If you implement an interface , Then you must implement all the abstract methods in the interface ,. Otherwise, it is necessary to add abstract modification
An abstract class , Implement an interface , Can achieve 0~N Abstract methods
1.8 There can be static methods , There can be default Method ( It can be understood as a member method )
Static methods , Call with the interface name
default Method needs to be called by the sub implementation class , You can also override
1.9 Start Support private Method
If both interfaces and abstract classes can do one thing , Interface is preferred , Because this will preserve the inheritance of the class


5. object
Object Is the ancestor of all classes , yes java The root class provided in
5.1 Equals
equals() : The method is designed for , Used to compare whether two objects are equal , however Default comparison address

5.2 Finalize
finalize : This method will be called automatically when the garbage is collected , Unordered programmers manually call
Object Medium finalize Method , Nothing has been done , You need to rewrite it according to your needs

5.3 toString
toString : Represents the string representation of the current object
When printing a reference type variable , Will automatically call the toString Method, but the default is to print the address

边栏推荐
- The textfield is encapsulated by the flutter itself, which causes the data display to be disordered when the data in the list is updated.
- _ 19_ IO stream summary
- Android修行手册之Kotlin - 自定义View的几种写法
- Xinlou: Huawei's seven-year building journey of sports health
- Navicat premium 15 for MAC (database development tool) Chinese version
- Based on neural tag search, the multilingual abstracts of zero samples of Chinese Academy of Sciences and Microsoft Asiatic research were selected into ACL 2022
- Time wheel and implementation analysis of time wheel in go zero
- 2021, committed to better development
- Deadlock, thread communication, singleton mode
- Prototype chain analysis
猜你喜欢
Take you to the open source project of smart home: the preliminary configuration of zhiting home cloud and home assistant+ homebridge

Sleep formula: how to cure bad sleep?

Don't underestimate the integral mall, its role can be great!

Bypass technology to talk about 'cross end'

GO语言-什么是临界资源安全问题?

Don't underestimate the integral mall, its role can be great!

How to reload the win10 app store?

The style of the mall can also change a lot. DIY can learn about it!

What plug-ins are available for vscade?
MySQL installation tutorial
随机推荐
Introduction to MgO 256gb NAND flash chip
Classic deadlock scenario of multithreading and its solution (philosopher dining problem)
绕过技术聊'跨端'......
Lecun predicts AgI: big model and reinforcement learning are both ramps! My "world model" is the new way
Don't underestimate the integral mall, its role can be great!
八种button的hover效果
iVX低代码平台系列详解 -- 概述篇(一)
赫尔辛基交通安全改善项目部署Velodyne Lidar智能基础设施解决方案
Based on neural tag search, the multilingual abstracts of zero samples of Chinese Academy of Sciences and Microsoft Asiatic research were selected into ACL 2022
f_ Read function [easy to understand]
Rxjs TakeUntil 操作符的学习笔记
[untitled]
揭秘GaussDB(for Redis):全面对比Codis
Deadlock, thread communication, singleton mode
Multiple decorators decorate a function
DOM event flow, event delegate
Helsinki traffic safety improvement project deploys velodyne lidar Intelligent Infrastructure Solution
Alvaria宣布客户体验行业资深人士Jeff Cotten担任新首席执行官
Tensorflow loading cifar10 dataset
Converting cifar10 datasets