[Java in NetBeans] Lesson 06. Custom classes
这个课程的参考视频和图片来自youtube。
主要学到的知识点有:
- 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
public class Foo
{
private int _x; // if class members, and not public, start with underscore. public Foo()
{
this(1);
} public Foo(int x)
{
_x = x;
}
}
- 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 "_".
public class Foo
{
private int x; public Foo()
{
this(1);
} public int setX(int x)
{
this.x = x;
}
}
- Use get/set methods to control access to private variables.
[Java in NetBeans] Lesson 06. Custom classes的更多相关文章
- [Java in NetBeans] Lesson 04. Class / Objects
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: Class: Blueprint for an object. (e.g. dog is a class) Object: cust ...
- [Java in NetBeans] Lesson 09. Switch / If-Else Ladder
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: 1. Nested If-else statement (if-else ladder) /** * 90 and above == ...
- [Java in NetBeans] Lesson 07. JavaDoc and Unit Tests
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: 1. organize code into packages Create a package if want to make th ...
- [Java in NetBeans] Lesson 05. Method/function
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: Define a method:(motivation: write one time, but use it many times ...
- [Java in NetBeans] Lesson 00. Getting Set-up for Learning Java
这个课程的参考视频在youtube. 主要学到的知识点有: set up needs Java SE JDK, NetBeans IDE class name should be the same l ...
- [Java in NetBeans] Lesson 17. File Input/Output.
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: We want to handle the bad Error. (e.g bad input / bugs in program) ...
- [Java in NetBeans] Lesson 16. Exceptions.
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: We want to handle the bad Error. (e.g bad input / bugs in program) ...
- [Java in NetBeans] Lesson 15. Sorting and Searching.
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: Build in functions in java.util.Collections Need to implement a co ...
- [Java in NetBeans] Lesson 01. Java Programming Basics
这个课程的参考视频在youtube. 主要学到的知识点有: Create new project, choose Java Application. one .jar file/ package(.j ...
随机推荐
- MyISAM和InnoDB区别 及选择
MySQL默认采用的是MyISAM. MyISAM不支持事务,而InnoDB支持.InnoDB的AUTOCOMMIT默认是打开的,即每条SQL语句会默认被封装成一个事务,自动提交,这样会影响速度,所以 ...
- linux 下实用软件工具推荐
截图:Deepin-Screenshot 音乐:deepin-music netease-music 绘图工具:Draw.io Desktop (chrome extension) / www.pro ...
- centos linux7的一些操作
进入centos7的一些界面后,按ctrl+alt+F2,则可进入全shell界面,不过要登录root的密码: 从全shell转为gnome 界面窗口,按alt+F1: *************** ...
- js对象属性两种调用bug
jsobj.url_3[0]=url_3[1];这就错误jsobj.url_3[0]红色看成一个整体的0的属性,这就错了 TypeError: Cannot set property '0' of u ...
- 使用 git log、git diff 命令时出现 ESC[33 和 ESC[m 乱码的解决办法
经过搜索之后了解到,出现该问题的原因是 git 使用的默认分页程序是 less,而默认的直接运行 less 的话,会无法正确解析转义字符.但是如果以 -r 命令来运行 less 的话,就可以解决了.故 ...
- 浏览器下载Excel,直接打开显示乱码...
情景: 浏览器中点击下载文件有两个选项:[打开][下载] [打开]之后,提示["文件.xlsx"的文件格式和扩展名不匹配.文件可能已损坏或不安全.除非您信任其来源,否则请勿打开.是 ...
- CCPC-Wannafly Winter Camp Day3 Div1 - 排列
题目链接:https://zhixincode.com/contest/14/problem/A?problem_id=203 time limit per test: 1 secondmemory ...
- SQL Fundamentals: 子查询 || WHERE,HAVING,FROM,SELECT子句中使用子查询,WITH子句
SQL Fundamentals || Oracle SQL语言 子查询(基础) 1.认识子查询 2.WHERE子句中使用子查询 3.在HAVING子句中使用子查询 4.在FROM子句中使用子查询 5 ...
- 2015年蓝桥杯省赛A组c++第3题
/* 小明发现了一个奇妙的数字.它的平方和立方正好把0~9的10个数字每个用且只用了一次. 你能猜出这个数字是多少吗? 请填写该数字,不要填写任何多余的内容. */ #include<cstdi ...
- 《HTTP - https》
一:HTTP 缺点? - 明文通讯(也是最受诟病的一个缺点) - 不验证对方的身份(你说你是你?你怎么证明你是你呢?) - 无法验证报文的完整性,可能已经被篡改(在挨打的边缘,来回试探) 二:HTTP ...