This is the 20th day of my participation in the August Text Challenge.More challenges in August

Hello, I’m Grey Ape! A super bug writing program ape! With adhere to create technology, with the fingertip knock the future! Like many of you, I am a “creator” on the Java path. Also want to rely on technology to change the future, change the world! Because we believe that every keystroke can make life smarter and the world more interesting! In this column, The Java Core Interview Guide, document our day 10 to prepare for our dreams!

Object-oriented aspects of the interview questions and we summarized several days, divided the content into several sections and knowledge points, today to continue to share the last part with you,

1. What is the difference between aggregate and combinatorial relationships?

The aggregation relation describes the ownership relation between two objects. The simulation has (HAS-A) relation. An object can be owned by several aggregation objects. If an object is exclusive to an aggregation object, the association between that object and the aggregation object is called a composition.

If a person drives a car, and a car can be driven by more than one person, this is the aggregation relationship, a person has an ID card, an ID card can only be owned by a person, this is the combination relationship.

2. What are “strong is relation” and “weak is relation”, and how to reflect these two relations respectively in the code?

“Strong is relation” describes direct inheritance relation, “weak is relation” describes a class has some attributes, “strong is relation” can be represented by class inheritance, “weak is relation” can be represented by interface.

3. What do cohesion and coupling mean? How do the design principles of classes require cohesion and coupling?

Cohesion refers to the relevance and closeness of elements within a class or module, and coupling refers to the closeness of connections between different classes or modules. The principle of class design requires high cohesion and low coupling, that is, the same class or module has strong internal correlation, the correlation between different classes or modules should be as little as possible, and each class or module should exist independently as much as possible.

4. How to determine whether inheritance or aggregation should be used between two classes?

If the relationship between two classes is yes, the inheritance relationship is used. If two classes are “relational,” use an aggregation relationship.

If the Labrador is a dog, the relationship between the labrador and the dog is inherited,

“Classroom” has “student” inside, then classroom and student are aggregation relation

5. How to achieve encapsulation of data domain?

One way to ensure encapsulation of a data field in a class is to add a private modifier to it to hide its visibility and avoid direct access to the data field from outside. If the value of a data field needs to be read externally, the reader GET method is provided. If you need to modify the value of a data field externally, provide the setter set method. If a method is only used inside the class, use the private modifier for the method to avoid calling the method from outside. This ensures encapsulation of the data domain.

6. What are the meanings of serialization and deserialization?

The process of converting an object to a byte sequence is called object serialization, and the process of restoring a byte sequence to an object is called object deserialization

What is the role of the Serializable interface? What information does this interface contain?

Or: How can an object be identified as serializable?

The Serializable interface identifies whether an object is Serializable. Instances of a class are Serializable only if the class implements the Serializable interface, which is the identity interface and does not contain any data fields or methods.

8, what is the role of the keyword TRANSIENT?

When a data domain cannot be serialized, or does not want to serialize a data domain, add the keyword TRANSIENT to the data domain, and the data domain will be ignored in the serialization process.

What is the function of the Class Class?

The purpose of the Class Class is to hold information about the Class that each object belongs to while the program is running and analyze the Class while the program is running.

10, What are the common methods of the Class Class?

The most common method in the Class Class is getName, which returns the name of the Class. The Class Class also has methods that return the data fields, methods, and constructors of the Class.

Methods whose names do not include Declared will only return public data fields, methods, and constructors,

Methods whose method names are Declared return all data fields, methods, and constructors. Methods whose names end in s return all data fields, methods, and constructors; methods whose names do not end in s return individual data fields, methods, and constructors.

Today’s summary

Today, I share with you the last part of the object-oriented interview questions. The content of this part is mainly to master two points, one is to understand serialization and deserialization operations, and the other is to be familiar with reflection mechanism, among which reflection is a relatively important point, and will often be used in the development of the content.

Up to now, the object-oriented related interview questions and we summed up the end, if you have encountered other related interview questions, welcome to the comment section, I will put you put forward the summary of the article ‘, welcome to join the comments section punch card learning! Friends can also add my friends in the left side to discuss learning!

I’m a little grey ape, and I’ll see you next time!