Object-oriented programming: As the name suggests, Object-Oriented Programming or OOPs refers to languages that uses objects in programming. Object-oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism etc in programming. The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function.(OOP的主要目的是将数据和对其进行操作的功能绑定在一起,以便除该功能外,代码的其他任何部分都无法访问此数据。)

Object Oriented Programming (OOPs) Concept in Java - GeeksforGeeks

  1. 在这其中,指出oops(面向对象的编程)主要目的是将数据和函数结合在一起,bind说明两者是绑定。
  2. 当然inheritance, hiding, polymorphism etc(继承,隐藏,多态等)等内容。。。

下面学习一波面向对象的语言的特性:

面对对象的三大特征:

1. polymorphism多态:

Polymorphism in Java - GeeksforGeeks

. In other words, polymorphism allows you to define one interface and have multiple implementations

即一个函数名字有着许多不同的含义(根据传入值类型,数量的不同而改变),以实现更多。

也就是说可以创建多个同名的函数

在现实生活中:我们对于一个名字会有许多的不同的理解,这取决于环境的不同。同样的在面向对象的特性(多态)吧,便实现了这一真实世界中的现象,赋值给了编程。

所谓多态就是指一个类实例的相同方法在不同情形有不同表现形式。多态机制使具有不同内部结构的对象可以共享相同的外部接口。这意味着,虽然针对不同对象的具体操作不同,但通过一个公共的类,它们(那些操作)可以通过相同的方式予以调用。

最常见的多态就是将子类传入父类参数中,运行时调用父类方法时通过传入的子类决定具体的内部结构或行为。

2. Inheritance:继承

继承就是一个函数可以使用其他函数的内容(field和methods即函数和变量)。

分为三类:

  • Super Class: The class whose features are inherited is known as superclass(or a base class or a parent class).超类:被其他类继承
  • Sub Class: The class that inherits the other class is known as subclass(or a derived class, extended class, or child class). The subclass can add its own fields and methods in addition to the superclass fields and methods.子类:继承其他类
  • Reusability: Inheritance supports the concept of “reusability”, i.e. when we want to create a new class and there is already a class that includes some of the code that we want, we can derive our new class from the existing class. By doing this, we are reusing the fields and methods of the existing class.体现了其可以重复利用代码,不必多次重复去编写重复的内容。

关键词是 extends

3. Encapsulation:封装

封装:就是将该类所操作的数据和类,封装在一起。这是一种保护机制,可以使得其他的代码无法获取到被封装起数据,以此保护了数据。

除了三大基本特征以外:其实共七大(有重复)特征

将数据简化,只提供需要的数据给用户

抽象是通过接口和抽象类来实现的。我们可以使用接口实现100%的抽象。

  • Class 类(类是用户定义的蓝图或原型,从中可以创建对象)
  • Object 对象:State ,Behavior, Identity
  • Method :函数如下图(但在java中,只能存在于类下面,不可以独立像c,cpp,python一样出现)

1