[Java in NetBeans] Lesson 06. Custom classes
生活随笔
收集整理的這篇文章主要介紹了
[Java in NetBeans] Lesson 06. Custom classes
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
這個(gè)課程的參考視頻和圖片來自youtube。
? ? 主要學(xué)到的知識(shí)點(diǎn)有:
- Constructors: A special method called when an object of the class is created
- property pattern and encapsulation(封裝): hide the implementation details from the user, so when the class is been inherited, only the methods, but not the members.?
- this: simply refers to the current class.?
- Also allow us to call other constructor in one constructor
?
- Overload: The method with different parameter but same method name. (for example, the constructors. Java will automatic search for the constructors that fits the parameters passed in)
? ? ? ? ? ? ?e.g. Foo foo = new Foo(8); will automatic search for the second constructor "public Foo(int x)".
- Every class should have a constructor. But the body can be empty.?
- Declare variables as private as possible. Can create getter and setter for the variables to control access to private variables.? based on the?encapsulation(封裝) concept.?
- Initialize all private variables in constructor. (if not, make them final)
- this disambiguates method parameters from private members, but will name the members with _(unless it is public). Below is an example without "_".
- Use get/set methods to control access to private variables.?
轉(zhuǎn)載于:https://www.cnblogs.com/Johnsonxiong/p/10086486.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的[Java in NetBeans] Lesson 06. Custom classes的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 小人 具体定义是什么? 财富值28
- 下一篇: kdnra电视是什么牌子