Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC1351 9/6/2011 Where are we?. Polymorphism // Use dynamic lookup to allow different data types to be manipulated // with a uniform interface. public.

Similar presentations


Presentation on theme: "CSC1351 9/6/2011 Where are we?. Polymorphism // Use dynamic lookup to allow different data types to be manipulated // with a uniform interface. public."— Presentation transcript:

1 CSC1351 9/6/2011 Where are we?

2 Polymorphism // Use dynamic lookup to allow different data types to be manipulated // with a uniform interface. public class FlameThrower implements Weapon { public void inflict(Target t) { t.fireDamage(6); } public class Sword implements Weapon { public void inflict(Target t) { t.cuttingDamage(3); }... Weapon w = new Sword(); w.inflict(target); // Dynamic lookup of Sword's inflict method w = new FlameThrower(); w.inflict(target); // Method comes from object type, not variable type

3 Vocabulary super class sub class accessor mutator polymorphism callback observer pattern side effect constant object

4 Types Eight primitive types int - signed, 4 bytes double - 8 bytes float - 4 bytes short - signed, 2 bytes long - signed 8 bytes char - unsigned, 2 bytes byte - signed, 1 byte boolean - two states

5 Primitive vs. Object Primitives passed by value automatic variables are allocated off the stack wrappers for all primitives are in java.lang wrappers provide parse methods Objects passed by reference automatic variables are allocated with new and come from the heap

6 Keywords - Know what they mean interface class abstract public private package import static final

7 Types Objects All classes extend class Object Objects all have public String toString() String/StringBuffer public char charAt(int pos) int length() String substring(int start,int end) int indexOf(char)

8 Types Arrays allocated with new final int field named length Enums A special type of object to represent a finite set of values

9 Conventions All class names are capitalized First letters of words are capitalized, e.g. GiantRat, BankAccount, etc. All method names start with lower case constants (final static) are in all caps and use the underscore to separate words, e.g. MIN_VALUE

10 Inheritance You can only extend one class Abstract classes have some undefined methods Interfaces have only undefined methods, or constants

11 Inner Classes Static Inner Classes – declared inside another class – does not have access to fields of enclosing class Non-static Inner Classes – declared inside another class – has access to fields of enclosing class Anonymous Inner Classes – a non-static inner class without a name


Download ppt "CSC1351 9/6/2011 Where are we?. Polymorphism // Use dynamic lookup to allow different data types to be manipulated // with a uniform interface. public."

Similar presentations


Ads by Google