Object-Oriented Java OCA
Object-Oriented Java OCA
Class, Method, Variable, Scope
Inherit Encapsulation 封装 polymorphism 多态
组合与关系
1. Class, Method, Variable, Scope
8 Basic Type
boolean char byte short int long float double
Currency BigDecimal
Method
<Access Modifier> <Return Type> <Method Name> <Parameter List> {Body}
{Body} return void
Override and Overwrite
* Override - Actions and decisions are overriden. * Overload - Information is overwritten.
Pass By Value | Pass By Refernece
* Three return types for methods; must use one: primitive type, reference type, or void
Scope
1. Local Variable 2. Method Parameter 3. Instance Variable
Constructor Function / default Constructor / Constructor Overload
this - super
* super use parent class in current class method or contstructor
Static Method / Variable
Inherit, Encapsulate
Abstract
Implement, Interface
Access Modifier
Encapsulate Setter / Getter
ID | Abstract Class | Interface |
---|---|---|
1 | An abstract class can extend only one class or one abstract class at a time | An interface can extend any number of interfaces at a time |
2 | An abstract class can extend another concrete (regular) class or abstract class | An interface can only extend another interface |
3 | An abstract class can have both abstract and concrete methods | An interface can have only abstract methods |
4 | In abstract class keyword “abstract” is mandatory to declare a method as an abstract | In an interface keyword “abstract” is optional to declare a method as an abstract |
5 | An abstract class can have protected and public abstract methods | An interface can have only have public abstract methods |
6 | An abstract class can have static, final or static final variable with any access specifier | interface can only have public static final (constant) variable |
Polymorphism
Set Theory Transitive
* Inherit A ∪ B ∪ C ∈ R * Polymorphism A ∩ B ∩ C ∈ R
overloading
means there are several methods present in a class having the same name but different types/order/number of parameters.