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

How to use the object-oriented inner class of Java

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

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!

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

Development

Wechat

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

12
Report