这个课程的参考视频和图片来自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的更多相关文章

  1. [Java in NetBeans] Lesson 04. Class / Objects

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: Class: Blueprint for an object. (e.g. dog is a class) Object: cust ...

  2. [Java in NetBeans] Lesson 09. Switch / If-Else Ladder

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: 1. Nested If-else statement (if-else ladder) /** * 90 and above == ...

  3. [Java in NetBeans] Lesson 07. JavaDoc and Unit Tests

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: 1. organize code into packages Create a package if want to make th ...

  4. [Java in NetBeans] Lesson 05. Method/function

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: Define a method:(motivation: write one time, but use it many times ...

  5. [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 ...

  6. [Java in NetBeans] Lesson 17. File Input/Output.

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: We want to handle the bad Error. (e.g bad input / bugs in program) ...

  7. [Java in NetBeans] Lesson 16. Exceptions.

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: We want to handle the bad Error. (e.g bad input / bugs in program) ...

  8. [Java in NetBeans] Lesson 15. Sorting and Searching.

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有: Build in functions in java.util.Collections Need to implement a co ...

  9. [Java in NetBeans] Lesson 01. Java Programming Basics

    这个课程的参考视频在youtube. 主要学到的知识点有: Create new project, choose Java Application. one .jar file/ package(.j ...

随机推荐

  1. git rebase 操作撤销

    git rebase可以更改提交历史,在不影响别人的情况下,能够重整git树. 但如果git rebase操作失误,却在push后才发现,怎么撤销rebase操作呢? 使用git reflog + g ...

  2. centos 7 配置hadoop与spark

    cd /home mkdir shixi_enzhaocd shixi_enzhaomkdir suaneccd suanecmkdir installsmkdir libsmkdir scripts ...

  3. Nodejs----基本数据类型

    Nodejs基本数据类型: nodejs的基础JavaScript(脚本语言). 而大多数的

  4. cuteftp9破解及安装、使用

    一.破解: 参考:https://jingyan.baidu.com/article/ca00d56c4e43b2e99febcf70.html 1. 首先下载cuteftp替换文件及cuteftp9 ...

  5. 20165311 预备作业3 Linux安装及学习

    Linux安装 由于回家没有带笔记本,所以把VirtualBox安装在家里的台式上,回学校之后再重新在自己的笔记本上安装虚拟机.参考<基于VirtualBox安装Ubuntu图文教程>,整 ...

  6. [No000010A]Git3/9-创建版本库

    什么是版本库呢?版本库又名仓库,英文名repository,你可以简单理解成一个目录,这个目录里面的所有文件都可以被Git管理起来,每个文件的修改.删除,Git都能跟踪,以便任何时刻都可以追踪历史,或 ...

  7. [No0000E4]C# 常量

    常量是固定值,程序执行期间不会改变.常量可以是任何基本数据类型,比如整数常量.浮点常量.字符常量或者字符串常量,还有枚举常量. 常量可以被当作常规的变量,只是它们的值在定义后不能被修改. 整数常量 整 ...

  8. find实现特殊功能示例

    find列出目录下所有文件: # find /shell-script/ # find /shell-script/ -print find列出文件夹中所有开头为text的文件,参数-iname意思忽 ...

  9. [administrative][CentOS][NetworkManager] networkmanager (二)

    [administrative][CentOS][NetworkManager] 万恶的NetworkManager到底怎么用 工程文档: https://wiki.gnome.org/Project ...

  10. [development][C] linux 设置线程名称

    两个API, 都是linux的. 不是POSIX, 是GNU?  傻傻搞不清楚. 1. pthread_setname_np / pthread_setname_np 2. ptctl 带 PR_GE ...