encapsulation, inheritance, composition. class methods can be either void or return can have...
TRANSCRIPT
Encapsulation, Inheritance, Composition
Class MethodsCan be either void or returnCan have parameters or notMust be staticShould be publicKnow how to invoke (call)Be able to evaluate
Object MethodsCan be either void or returnCan have parameters or notMay be public or private (helper)Know how to invoke (call)Be able to evaluate
ParametersActual vs FormalFormal
In the method definitionMust have data types
ActualIn the method callCannot have data typesMust match the formal parameters in type,
quantity and sequence
Void methodsCan have parameters or notHave the keyword void in the heading
Return methodsCan have parameters or notDo not have the keyword void in the headingHave a return statement in the body of the
method
InheritanceDefinitionExamplesIs-ASuperclassSubclassExtendsConstructor of superclass called first
superUsed in constructor to invoke the constructor
of the super classMust be used to pass information to the
constructor of the super classMust be used if the super class has no default
constructorMust be first in the constructorUsed in other methods to invoke methods of
the super class
Inheritance Examplepublic class superClass{ private int var1; public superClass(int v1) { var1 = v1; }}public class subClass extends superClass{
private int var2; public subClass(int v1, int v2) { super(v1); var2 = v2; }}
Multi-Level InheritanceKnow which constructor is called firstKnow how to pass information to the super
constructor and the super constructors of the classes above that.
Watch for tricky questionsWatch for tricky assignmentsKnow which constructor is called firstKnow which method is called – first it looks in
the sub class for the method, then the super class.
DefinitionExamplesHas-AConstructor of container class called firstConstructor of contained class called last
Composition
Composition Examplepublic class Part{ private int var1; public Part(int v1) { var1 = v1; }}public class Container {
private int var2; private Part var3; public subClass(int v1, int v2) { var2 = v2; var3 = new Part(v1); }}