Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Encapsulation of three object-oriented Features of java

Shulou Source: shulou.com Published: 2022-06-03 07:16:57 10月04日 Update

In fact, in the process of doing Java development or at the beginning of learning, I didn't think so much, but I just did it all the time. But since I did a certain project, I found that very often, people's energy and brainpower are limited, they always forget what they have done or learned before, and they slowly start the habit of writing blogs. First, they can strengthen themselves. Second, you can share it with others and discuss it with everyone, because everyone's opinions will make you get different things from it, just like a teacher he met before. he said that every time he talked about object-oriented, he had a different feeling, so it was also an encouragement to himself and programmers who were still struggling on the front line. I hope that when we look back many years later, we have fought so hard.

First of all, let's briefly talk about my understanding of encapsulation.

To put it simply, you create a class and show untrusted class hides to its properties and methods for trusted classes, that is, property privatization methods are made public.

Again, its advantage is that attributes can be protected, coupling can be reduced, and members can be better and more precisely controlled.

Let's demonstrate encapsulation with the simplest example.

Public class FengZhuang {

Private String name

Private int age

Private String sex

Private double weight

Double heigh

/ / method of assigning values to age

Public void setAge (int age) {

If (age > 0 & & age

Tags: Methods encapsulation properties differences things that is time presentation objects precision gratitude first line that is from examples blogs trustworthy great gods benefits examples Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Huawei Apple vpn OPPO Reno