Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Encapsulation of three object-oriented Features of java

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report