Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 Inheritance Review CSC 171 FALL 2004 LECTURE 19

2 READING Read Horstmann, Chapter 11 Look at Chapter 12 – Will not be on MT or Final – One lab Begin Reading Chapter 13

3 Object: The Cosmic Superclass All classes extend Object Most useful methods: – String toString() – boolean equals(Object otherObject) – Object clone() // Clone copies objects

4 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

5 Abstract Methods public abstract class BankAccount { public abstract void deductFees(); } Can’t be instantiated

6 ___________________ is a method for extending existing classes by adding methods and fields.

7 __Inheritance__________ is a method for extending existing classes by adding methods and fields.

8 The more general class is called a _____________________. The more specialized class that inherits from it is called the _____________________.

9 The more general class is called a ___SUPERCLASS___. The more specialized class that inherits from it is called the ____SUBCLASS__________.

10 Every class extends the _____________ class either directly or indirectly.

11 Every class extends the ___Object______ class either directly or indirectly.

12 Inheriting from a class differs from realizing an interface. The subclass inherits ________________ and ______________ from the superclass.

13 Inheriting from a class differs from realizing an interface. The subclass inherits _________behavior_______ and ___state___________ from the superclass.

14 One advantage of inheritance is _______________________.

15 One advantage of inheritance is ___code reuse___________.

16 When defining a subclass, you specify added ___________________, added _______________, and changed or ____________________ methods.

17 When defining a subclass, you specify added _instance fields________, added _methods___________, and changed or _overridden________ methods.

18 Sets of classes can form complex inheritance ________________________.

19 Sets of classes can form complex inheritance _____hierarchies______.

20 A subclass has __________ access to private fields fo its superclass.

21 A subclass has _____NO___ access to private fields of its superclass.

22 Use the ____________________ keyword to call a method of the superclass.

23 Use the _______super_______ keyword to call a method of the superclass.

24 To call the superclass constructor, you use the _____________ keyword in the ____________ statement of the subclass constructor.

25 To call the superclass constructor, you use the __super______ keyword in the __first______ statement of the subclass constructor.

26 A _________________ reference can be cast/converted to a ____________ reference, but not the other way around.

27 A ______subclass_____ reference can be cast/converted to a ___superclass____ reference, but not the other way around.

28 An _______________ method is one whose implementation is not specified.

29 An __abstract____ method is one whose implementation is not specified.

30 An ___________________ class cannot be instantiated.

31 An _____abstract________ class cannot be instantiated.

32 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.

33 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.

34 A field or method that is not declared as public, private, or protected can be accessed by all classes in the same ______________.

35 A field or method that is not declared as public, private, or protected can be accessed by all classes in the same _package____.

36 ____________________ features can be accessed by all subclasses and all classes in the same package.

37 _Protected_______ features can be accessed by all subclasses and all classes in the same package.

38 You should define the __________________ method to yield a string that describes the object state.

39 You should define the _toString________ method to yield a string that describes the object state.

40 You should define the ____________________ method to test whether two objects have equal state.

41 You should define the _____equals______ method to test whether two objects have equal state.

42 The ____________________________- method makes a new object with the same state as an existing object.

43 The ______clone______________- method makes a new object with the same state as an existing object.

44 Excercise Vehicle Car Truck Sedan Coupe PickupTruck SUV Minivan Bicycle Motorcycle

45 Excercise Student Professor TA Employee Secretary DepartmentChair Janitor SeminarSpeaker Person Course Seminar Lecture

46 CHAPTER 12 – MORE GUI Applications

47 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(); }

48 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 managers panel.setLayout(new BorderLayout());

49 Border Layout Border layout places components into positions (center, north, west, south, east) panel.add(textField, BorderLayout.SOUTH );

50 Border Layout Content pane of frame has border layout by default frame.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

51 Grid Layout Lays out components in rows and columns All components have the same size Add components left to right (top row first, then second row, etc.) panel.setLayout(new GridLayout(4, 3)); panel.add(button7); panel.add(button8); panel.add(button9); panel.add(button6);

52 Grid Layout

53 A Combo Box, Check Boxes, and Radio Buttons

54 Menu Items Pull-Down Menus Add menu items to the menu JMenuItem fileNew = new JMenuItem("New"); Add action listener to the menu item ActionListener l =...; fileNew.addActionListener(l);

55 Putting it all together

56 Menus


Download ppt "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."

Similar presentations


Ads by Google