560 likes | 577 Views
Inheritance Review. CSC 171 FALL 2004 LECTURE 19. READING. Read Horstmann, Chapter 11 Look at Chapter 12 Will not be on MT or Final One lab Begin Reading Chapter 13. Object: The Cosmic Superclass. All classes extend Object Most useful methods: String toString()
E N D
Inheritance Review CSC 171 FALL 2004 LECTURE 19
READING • Read Horstmann, Chapter 11 • Look at Chapter 12 • Will not be on MT or Final • One lab • Begin Reading Chapter 13
Object: The Cosmic Superclass • All classes extend Object • Most useful methods: • String toString() • boolean equals(Object otherObject) • Object clone() // Clone copies objects
Abstract Classes • We saw with Interfaces, a way to define a signature for a method, without implementation – requiring later implementation • We can do this in the context of inheritance using sub/superclass hierarchies using abstract methods and classes
Abstract Methods public abstract class BankAccount { public abstract void deductFees(); } • Can’t be instantiated
___________________ is a method for extending existing classes by adding methods and fields.
__Inheritance__________ is a method for extending existing classes by adding methods and fields.
The more general class is called a _____________________. The more specialized class that inherits from it is called the _____________________.
The more general class is called a ___SUPERCLASS___. The more specialized class that inherits from it is called the ____SUBCLASS__________.
Every class extends the _____________ class either directly or indirectly.
Every class extends the ___Object______ class either directly or indirectly.
Inheriting from a class differs from realizing an interface. The subclass inherits ________________ and ______________ from the superclass.
Inheriting from a class differs from realizing an interface. The subclass inherits _________behavior_______ and ___state___________ from the superclass.
When defining a subclass, you specify added ___________________, added _______________, and changed or ____________________ methods.
When defining a subclass, you specify added _instance fields________, added _methods___________, and changed or _overridden________ methods.
Sets of classes can form complex inheritance ________________________.
Sets of classes can form complex inheritance _____hierarchies______.
A subclass has __________ access to private fields fo its superclass.
A subclass has _____NO___ access to private fields of its superclass.
Use the ____________________ keyword to call a method of the superclass.
Use the _______super_______ keyword to call a method of the superclass.
To call the superclass constructor, you use the _____________ keyword in the ____________ statement of the subclass constructor.
To call the superclass constructor, you use the __super______ keyword in the __first______ statement of the subclass constructor.
A _________________ reference can be cast/converted to a ____________ reference, but not the other way around.
A ______subclass_____ reference can be cast/converted to a ___superclass____ reference, but not the other way around.
An _______________ method is one whose implementation is not specified.
An __abstract____ method is one whose implementation is not specified.
A field or method that is not declared as public, private, or protected can be accessed by all classes in the same ___________, which is usually not desirable.
A field or method that is not declared as public, private, or protected can be accessed by all classes in the same ____package_______, which is usually not desirable.
A field or method that is not declared as public, private, or protected can be accessed by all classes in the same ______________.
A field or method that is not declared as public, private, or protected can be accessed by all classes in the same _package____.
____________________ features can be accessed by all subclasses and all classes in the same package.
_Protected_______ features can be accessed by all subclasses and all classes in the same package.
You should define the __________________ method to yield a string that describes the object state.
You should define the _toString________ method to yield a string that describes the object state.
You should define the ____________________ method to test whether two objects have equal state.
You should define the _____equals______ method to test whether two objects have equal state.
The ____________________________- method makes a new object with the same state as an existing object.
The ______clone______________- method makes a new object with the same state as an existing object.
Vehicle Car Truck Sedan Coupe PickupTruck SUV Minivan Bicycle Motorcycle Excercise
Student Professor TA Employee Secretary DepartmentChair Janitor SeminarSpeaker Person Course Seminar Lecture Excercise
CHAPTER 12 – MORE GUI • Applications
FRAME BASED APPLICATION public static void main(String[] args) { JFrame appFrame = new JFrame(); appFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); appFrame.setContentPane(rectPanel); appFrame.pack(); appFrame.show(); }
Layout Management • Container arranges its components • By default, JPanel places components from left to right, then starts a new row if needed • Panel layout carried out by FlowLayout layout manager • Can set other layout managerspanel.setLayout(new BorderLayout());
Border Layout • Border layout places components into positions (center, north, west, south, east) panel.add(textField, BorderLayout.SOUTH);
Border Layout • Content pane of frame has border layout by defaultframe.getContentPane().add(textField, BorderLayout.SOUTH); • Border layout grows components to fit area • To avoid growth, place component into panel (with flow layout), then add panel to content pane