Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the object-oriented inner class of Java

Shulou Source: shulou.com Published: 2022-06-02 04:45:47 10月02日 Update

This article mainly shows you the "Java object-oriented internal classes how to use", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "Java object-oriented internal classes how to use" this article.

/ * * knowledge points: inner class 1. Definition of inner class 2. Advantages and disadvantages of inner classes 3. How external classes instantiate inner classes of other classes 4. The inner class is defined in the method. Static declares that the internal class topic: the mother is pregnant, the mother's nutrition determines the child's healthy growth ideas: 1. Abstract classes: mother (Mother), child (Baby) 2. Find out the class relationship: the child is in the mother Baby in Mother 3. Abstract the method: mother eating (eat) * / public class InnerClass {public static void main (String [] args) {/ / instantiating mother Mother mother = new Mother ("lucy"); / / mother eating apple mother.eat ("apple") / / Children draw nutrients from apples Mother.Baby baby = mother.new Baby (); baby.eat ();}} class Mother {private String name; private String food;// mother's food public Mother (String name) {this.name = name } public String getName () {return this.name;} public void setName (String name) {this.name = name;} / / Mother eats public void eat (String food) {this.food = food; System.out.println (this.name + "eat" + this.food) } class Baby {/ / the child absorbs nutrients from what the mother eats public void eat () {System.out.println ("the child absorbs nutrients from the mother's food" + food + ") The above is all the content of the article "how to use Java object-oriented inner classes". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Mothers children nutrition objects categories things content articles apples examples methods knowledge learning help health strengths and weaknesses children children ideas easy to understand Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Tech Info Microsoft Linux MySQL