06a-inheritance - CSE 143 Lecture 6 More ArrayIntList;...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 143 Lecture 6 More ArrayIntList ; Inheritance reading: 15.1 - 15.2; 9.1, 9.3 - 9.4 slides created by Marty Stepp http://www.cs.washington.edu/143/
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Finishing ArrayIntList • Let's add the following features to ArrayIntList : – a constant for the default list capacity – better encapsulation and protection of implementation details – a better way to print list objects
Background image of page 2
3 Class constants public static final type name = value ; class constant : a global, unchangeable value in a class – used to store and give names to important values used in code – documents an important value; easier to find and change later • classes will often store constants related to that type – Math.PI – Integer.MAX_VALUE , Integer.MIN_VALUE – Color.GREEN // default array length for new ArrayIntLists public static final int DEFAULT_CAPACITY = 10;
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 "Helper" methods • Currently our list class has a few useful "helper" methods: – public void checkResize () – public void checkIndex (int index, int min, int max) • We wrote them to help us implement other required methods. • We don't want clients to call these methods; they are internal. – How can we stop clients from calling them?
Background image of page 4
5 A private method private type name ( type name , . .., type name ) { statement(s) ; } •a private method can be seen/called only by its own class – encapsulated, similar to fields – your object can call the method on itself, but clients cannot call it – useful for "helper" methods that clients shouldn't directly touch private void checkIndex(int index, int min, int max) { if (index < min || index > max) { throw new IndexOutOfBoundsException(index); } }
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 18

06a-inheritance - CSE 143 Lecture 6 More ArrayIntList;...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online