40 likes | 180 Views
TUT #3 (of Tutorial3 :). Still CSCB07. Interfaces. Templates for Objects I nterface is a group of related methods with empty bodies Classes implement interfaces, agreeing to certain predefined behavior Cannot instantiate an interface(no constructors/variables)
E N D
TUT #3 (of Tutorial3 :) Still CSCB07
Interfaces • Templates for Objects • Interface is a group of related methods with empty bodies • Classes implement interfaces, agreeing to certain predefined behavior • Cannot instantiate an interface(no constructors/variables) • Used for code clarity, OO and defining behavior
Constructors • Create an instance of a class (i.e. an Object) • Platypus p1 = new Platypus(); • NO return type • Same name Class • Differ by input parameters (if more than one) • Purpose to initialize variables and other setup
Encapsulation • Restricts direct access to the internals of your object • Prevents unwanted behavior (users do not know how the class stores its data) • Simplifies usage, OO • Technique of making the fieldsprivateand providing access to the fields via public methods