当前位置:网站首页>Application and definition of interface
Application and definition of interface
2022-04-23 03:28:00 【Aiyou coffee】
Interface characterization : Interface cannot be instantiated ; Implementation classes must implement interfaces that are all methods ; Implementation classes can implement multiple interfaces ; Variables in an interface are static constants .
How to use interfaces : Design methods as needed , Implement all methods , Use... In a polymorphic way
The process : Definition Door abstract class ( There's a door , close ), Definition Lock Interface ( locked , The lock )
To write TheftproofDoor class ( Inheritance implementation interface ) Writing test classes ( There is an anti-theft switch to unlock the door )PS: A class can implement multiple interfaces
One . You can define a new interface , use extends To inherit the existing interface
You can define a new interface , use implements To implement all the methods in an interface
You can define a new interface , use implements To implement some methods in an interface
Two .C++ Support for multiple inheritance ,Java Support for single reinheritance ;C++ The danger of multiple inheritance is that a class may inherit different implementations of the same method , Will cause the system to crash ,Java A class in can inherit only one class , But multiple interfaces can be implemented at the same time , That is, the effect and function of multiple inheritance can be realized , The danger of multiple inheritance can also be avoided
3、 ... and . Defining a class inside another class is called an inner class . PS: External classes cannot directly use members and methods of internal classes , If the external class and the internal class have the same member variables or methods, the internal class .
Default member variable or method internal class , If you want to access the member variables of an external class , need this keyword
Four . Access the inner class in the outer class
grammar : Inner class External class objects = new External class ();
External class , Inner class Inner class object = External class objects new Inner class ();
5、 ... and . Inner class Static inner class
grammar new External class . Inner class () Syntax name
External class class name , Inside Inner class object name = new External class class name . Inner class class name ();
( Use static Declared inner class , Non accessible static External properties of )
No variables in the interface are constants , Because the default final
If a class has no parent , Then its parent is Object
The phone has three interfaces : Play , photograph , Connect to the network
版权声明
本文为[Aiyou coffee]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220619008863.html
边栏推荐
- Codeforces Round #784 (Div. 4)題解 (第一次AK cf (XD
- oracle 查询外键含有逗号分隔的数据
- ThreadLocal 测试多线程变量实例
- 浅学一下I/O流和File类文件操作
- Chapter 8 exception handling, string handling and file operation
- C-11 problem h: treasure chest 2
- 可以接收多種數據類型參數——可變參數
- Unity games and related interview questions
- Applet - more than two pieces of folding and expansion logic
- . net 5 Web custom middleware implementation returns the default picture
猜你喜欢

Code forces round # 784 (DIV. 4) solution (First AK CF (XD)

C abstract class

Unity basics 2

Problem a: face recognition
![Super easy to use [general excel import function]](/img/9b/ef18d1b92848976b5a141af5f239b5.jpg)
Super easy to use [general excel import function]

Visual programming - Experiment 1

2022 团体程序设计天梯赛 模拟赛 L2-3 浪漫侧影 (25 分)

Un aperçu des flux d'E / s et des opérations de fichiers de classe de fichiers

Unity Basics

淺學一下I/O流和File類文件操作
随机推荐
L3-011 直捣黄龙 (30 分)
MySQL installation pit
Detailed description of MySQL index [B + tree index, hash index, full-text index, overlay index]
Romantic silhouette of L2-3 of 2022 group programming ladder Simulation Competition (25 points)
AWS from entry to actual combat: creating accounts
幂等性实践操作,基于业务讲解幂等性
Scenario Title: how does system a use the page of system B
全新的ORM框架——BeetlSQL介绍
. net webapi access authorization mechanism and process design (header token + redis)
2022 group programming ladder game simulation L2-4 Zhezhi game (25 points)
Alphafpld upgrade alphafold multimer
Using jsonserialize to realize data type conversion gracefully
Build websocket server in. Net5 webapi
Applet - more than two pieces of folding and expansion logic
可以接收多種數據類型參數——可變參數
2022 团体程序设计天梯赛 模拟赛 1-8 均是素数 (20 分)
MySQL索引详解【B+Tree索引、哈希索引、全文索引、覆盖索引】
Test questions (2)
Unity knowledge points (ugui 2)
MySQL grouping query rules