Joke Collection Website - Blessing messages - Why does JAVA use encapsulation? What is the function of encapsulation? !
Why does JAVA use encapsulation? What is the function of encapsulation? !
Inheritance, if Class B inherits Class A, then Class B will have all the methods of Class A and can extend its own unique methods and properties. Take people as an example. People are paternal, so both men and women are inherited from people. In other words, both men and women have the attributes of height and weight, and they can also have their own unique attributes. For example, a "man" can have a "wife" attribute to indicate who his wife is. And women can have the attribute of' husband'.
Polymorphism, in java, the same method can have many different manifestations, specifically, it can be divided into overloading and rewriting. Overloading means that a method has the same method name but different parameter lists. For example:
Common string dialogue (string content); //The parameter is a string.
Public String talk (String content, int number)// parameters are 2, string and int.
Overloading means that subclasses inherit from the parent class and re-implement the methods of the parent class. The overloaded method name and parameters must be exactly the same.
Such as the parent class
Common String Dialog (String Content) (
System.out.print (content);
}
Subclasses inherit this class, so there is also a method talk, which redefines the implementation of this method.
Common String Dialog (String Content) (
system . out . println(" Hi "+content);
}
- Previous article:What does dj mean?
- Next article:How to set up WeChat message folding?
- Related articles
- Disappointed and sad to say, silence is deep despair.
- Send a notification message to the leader.
- Xiaomi SMS notification number. Will Xiaomi send the courier number to the mobile phone when delivering the goods?
- How to repay ABC's credit card?
- Happy birthday to my aunt.
- Electronic eyes capture short messages for processing within 30 days.
- How to open a data package with China Unicom card in Macau?
- Is Suning Financial app loan reliable?
- Value delivery of thinkphp posts
- What should I do if the oppo channel light encounter number is stolen?