Java Object-Oriented Learning Part II

Continue with the previous part: In the previous part, I learned some basic concepts of classes and objects, as well as one of the characteristics of objects: encapsulation.

1. Object-oriented

this method added:

I have learned this method before, and it is very clear about how to use it, but I still need to add some knowledge points:

Application examples:

Understanding the space and memory changes of the project is a qualitative help for writing code. This point is very important. For example: the following Account class, Customer class, and Bank class.

Object Oriented Inheritance:

Understanding of inheritance:

There are two angles to inheritance:

From top to bottom: class A, class B, class B has similar functions to class A, at this time, class B can be considered to inherit class A.

Bottom-up: Define classes B, C, D. It is found that B, C, and D have common attributes and methods. You can consider encapsulating them into class A and let BCD inherit class A.

Parent class: superclass; subclass: subclass.

 Introduce the role of breakpoints:

Breakpoints can help us understand the space changes of the stack and heap. Generally set when creating the object.

In this way, click Run, and the breakpoint will appear in this stack and heap space. Similar to the following: the breakpoint we set here is: Student s1=new Student();  

A distinction is made between overloading and overriding (again):

Supplements to the super() keyword:

scenes to be used:

 super calls the constructor:

 In fact, the super keyword solves a problem that when we call the test class to create an object of the subclass, it will create the properties of the parent class together in the heap. The reason is that the super() method is used by default. For example, the following figure explains:

Problems encountered:

When there is a constructor with parameters, must the super keyword with parameters be used to use inherited subclasses?

 

Written test questions (a great example):

Judge this in the non-inherited method. And an example of using the super() method by default in the inherited method.

 

Take a look at this object-oriented example:

This example targets a different object. have different properties. So what is its result? This example is quite convoluted.

 

A little thought: Although I am an auditor, should I not do the topic here? It shouldn't, and it needs to be done. The homework here can just check for gaps and make up for the omissions. Don’t think that doing the homework here will make your time shorter and stop doing it. The change I am talking about is to strive for all ways to help yourself improve faster and more usefully. So, of course, strive for change. !

Guess you like

Origin blog.csdn.net/qq_55928086/article/details/131934362