Presentation is loading. Please wait.

Presentation is loading. Please wait.

Encapsulation, Inheritance, Composition. Class Methods Can be either void or return Can have parameters or not Must be static Should be public Know how.

Similar presentations


Presentation on theme: "Encapsulation, Inheritance, Composition. Class Methods Can be either void or return Can have parameters or not Must be static Should be public Know how."— Presentation transcript:

1 Encapsulation, Inheritance, Composition

2 Class Methods Can be either void or return Can have parameters or not Must be static Should be public Know how to invoke (call) Be able to evaluate

3 Object Methods Can be either void or return Can have parameters or not May be public or private (helper) Know how to invoke (call) Be able to evaluate

4 Parameters Actual vs Formal Formal In the method definition Must have data types Actual In the method call Cannot have data types Must match the formal parameters in type, quantity and sequence

5 Void methods Can have parameters or not Have the keyword void in the heading

6 Return methods Can have parameters or not Do not have the keyword void in the heading Have a return statement in the body of the method

7 Inheritance Definition Examples Is-A Superclass Subclass Extends Constructor of superclass called first

8 super Used in constructor to invoke the constructor of the super class Must be used to pass information to the constructor of the super class Must be used if the super class has no default constructor Must be first in the constructor Used in other methods to invoke methods of the super class

9 Inheritance Example public 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; }

10 Multi-Level Inheritance Know which constructor is called first Know how to pass information to the super constructor and the super constructors of the classes above that.

11 Watch for tricky questions Watch for tricky assignments Know which constructor is called first Know which method is called – first it looks in the sub class for the method, then the super class.

12 Definition Examples Has-A Constructor of container class called first Constructor of contained class called last Composition

13 Composition Example public 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); }


Download ppt "Encapsulation, Inheritance, Composition. Class Methods Can be either void or return Can have parameters or not Must be static Should be public Know how."

Similar presentations


Ads by Google