Quiz 1 Review Lectures 7 13 Classes Objects

Quiz 1 Review Lectures 7 - 13

Classes & Objects l l A class is a user defined data type An object is an instance of a class

Lists & Iterators l Two implementations of List: – – l l Array. List Linked. List A List holds Objects Use an Iterator to access List elements sequentially.

Static & Final l l Keyword static: there is only one, and always one copy of the field or method. Static fields and methods can be accessed without instantiating the class. Static methods cannot reference non-static fields. Keyword final: the value of a variable in the Java table is fixed.

Packages, Scope, & Access l l Packages group classes with common purpose. Every variable has scope; a variable cannot be accessed outside of its scope. Java uses lexical scoping. Four kinds of access: public, private, package (default), and protected.

Inheritance l l Mechanism for creating class hierarchies. A subclass can only inherit from one superclass. All fields and methods are inherited by subclasses. keyword super allows subclasses to access a superclass' public or protected fields and methods.

Abstract Classes & Interfaces l Abstract classes – – l cannot be instantiated. can have both abstract and non-abstract methods. Interfaces – – – a contract to implement all specified methods are public and abstract by default fields are public and final by default

Sample Quiz Problem l l l We are going to design the graphical display for a WYSIWYG editor. A graphical element is a drawing within a rectangle with a point to hold its position on the screen. Every character is a graphical element. A list of characters comprises a line, which is also a graphical element. A list of lines comprises a paragraph, which is also a graphical element.

Add Classes. . . l l Graphical. Element Character Line Paragraph

Add Fields To Store … l l l Top-left corner of an element Height Width String representation of a character Style constants to indicate bold, italic, or underlined characters.

Add Methods to. . . l l Draw the graphical element Access fields of the classes

Create an Interface l l To perform spell checking Which classes will implement this interface?
- Slides: 12