Package of Java object-oriented three features

Source: Internet
Author: User


In fact, has been in the process of doing Java development or just beginning to learn the time did not think so much, are simply to do, but since doing a project also slowly found that a lot of time, people's energy and brain is limited, will always forget what has been done or learned things, slowly began to write the habit of blogging, One can be self-reinforcing, two can be shared to others can discuss with you, because everyone's opinion will let you get different things, just like a teacher who met before, he said that every time he told the object-oriented have a different feeling, So it is also a kind of encouragement to themselves and the first-line programmer, hope that after many years we think back, we have been so hard to fight.

First of all, my understanding of encapsulation is simple.

The simple thing to say is that you create a class that displays untrusted classes for the properties and methods of a trusted class hidden, that is, the property privatization method is open

Again, the benefit is that you can protect the properties, reduce coupling, and better control the members.

Below is a demonstration of the next package with one of the simplest examples

public class FengZhuang {
private String name;
private int age;
Private String sex;
private double weight;
Double Heigh;
How to assign an age value
public void Setage (int.) {
if (age > 0 && age<120) {
This.age = age;
}else{
System.out.println ("Too old or too small");
}
}
Methods to get the age value
public int getage () {
return age;
}
public void mm () {
System.out.println ("mm");
}
}

Although the above example is relatively simple, a simple demonstration of the package should be possible.

Hope that the way the great God to correct and exchange, grateful!!!


This article is from the "Java" blog, so be sure to keep this source http://4534508.blog.51cto.com/4524508/1960927

Package of Java object-oriented three features

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.