Java Notes: Classes, Methods, and Interface

Comprehend

  • The method name and return type are mandatory in a method declaration. Even though you are not required to specify a modifier in a method declaration, the default modifier is assigned to the method, if you don’t declare one.
  • A static variable belongs to the class and not to a particular instance of the class, and therefore is initialized when the class is loaded, and before the class is instantiated.
  • Because a static method belongs to a class and not to a particular instance of the class, it cannot access the nonstatic methods and variables of the class in which it is defined.
  • An instance of an inner class can only exist in an instance of the outer class, and has direct access to all the instance variables and methods of the outer instance.
  • If you make a super call or a this call, it must be in the beginning of a constructor. That means you can make either a super call or a this call, but not both.

Look Out

  • The variable-length parameters list must appear last in the parentheses of a method and it consists of a data type, three dots, and a name, in that order.
  • A Java class cannot inherit from more than one class, but it can inherit from one class and one or more interfaces.
  • The class that inherits from an interface must provide implementation for all the methods that are declared in the interface if the class is not abstract.
  • An interface can extend another interface but it cannot implement another interface or a class.

Memorize

  • If you do not provide any constructor for a class you write, the compiler provides the default constructor for that class. If you write at least one constructor for the class, the compiler provides no constructor.
  • If you don not make a this or a super call in the beginning of a constructor, the compiler places a super() call there.
  • You use the keyword extends to write a derived class that inherits from a parent class, and use the keyword implements to write a class that inherits from an interface.
  • The methods in an interface are inherently public and abstract, and the variables in the interface are inherently public, final, and static.
118188.html

HIMMEL 2007-05-17 22:47 发表评论
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值