THE UNIVERSITY OF AUCKLAND
|
|
- Dorcas Loren Watson
- 6 years ago
- Views:
Transcription
1 VERSION COMPSCI 230 THE UNIVERSITY OF AUCKLAND SECOND SEMESTER, 2011 Campus: City Computer Science TEST Software Design and Construction (Time Allowed: 50 MINUTES) Note: The use of calculators is NOT permitted. Compare the test version number on the Teleform sheet supplied with the version number above. If they do not match, ask the supervisor for a new sheet. Enter your name and student ID on the Teleform sheet. Your name should be entered left aligned. If your name is longer than the number of boxes provided, truncate it. Answer Section A of Multiple-choice questions on the Teleform answer sheet provided. Answer Section B in the space provided in this booklet. Attempt all questions. Use a dark pencil to mark your answers in the multiple choice answer boxes on the Teleform sheet. Check that the question number on the sheet corresponds to the question number in this question/answer book. If you spoil your sheet, ask the supervisor for a replacement. Write your answers in the space provided in the short answer section. Write as clearly as possible. The space provided will generally be sufficient but is not necessarily an indication of the expected length. Extra space is provided at the end of this test booklet. An appendix with a simplified API is included on the last page. You may detach this appendix. Surname: First Name(s): Student ID: Login Name(UPI): MARKERS ONLY Section Marks Of A 26 B 24 Total 50
2 VERSION COMPSCI 230 SECTION A MULTIPLE CHOICE QUESTIONS For each question, choose the best answer according to the information presented in lectures. Select your preferred alternative on the Teleform answer sheet provided. The following FIVE questions relate to the classes given below: class A { int x; A() { this(100); A(int x) { this.x = x; public String tostring() { return "A:" + x; class B extends A { int x = 10; int y = x+1; B() { B(int y) { this.y = this.y + y; B(int x, int y) { super(x); this.y = this.y + y; public String tostring() { return "A:" + super.x + ", B:(" + x + "," + y + ")"; Question 1 [1 mark] What will be printed after executing the following code fragment? A a1 = new A(); System.out.println(a1); (a) A:0 (b) A:100 (c) B:1 (d) B:100 (e) A:1
3 VERSION COMPSCI 230 Question 2 [1 mark] What will be printed after executing the following code fragment? A a2 = new A(10); System.out.println(a2); (a) A:10 (b) A:0 (c) B:100 (d) B:10 (e) A:100 Question 3 [2 marks] What will be printed after executing the following code fragment? B b1 = new B(); System.out.println(b1); (a) A:100, B:(100,101) (b) A:10, B:(100,101) (c) A:10, B:(10,11) (d) A:100, B:(10,11) (e) None of the above Question 4 [2 marks] What will be printed after executing the following code fragment? B b2 = new B(20); System.out.println(b2); (a) A:100, B:(10,131) (b) A:100, B:(100,121) (c) A:100, B:(10,31) (d) A:20, B:(10,31) (e) A:0, B:(10,1) Question 5 [2 marks] What will be printed after executing the following code fragment? B b3 = new B(20, 50); System.out.println(b3); (a) A:20, B:(20,71) (b) A:100, B:(10,61) (c) A:20, B:(10,61) (d) A:100, B:(100,151) (e) A:0, B:(20,51)
4 VERSION COMPSCI 230 The following FOUR questions relate to the classes given below: class A1 { int x=10; public void method() { System.out.print("A:" + this.x + " "); class B1 extends A1 { int x=20; public void method() { System.out.print("B:" + this.x + " "); public static void main(string args[]) { A1 p = new A1(); B1 q = new B1(); //... Question 6 [1 mark] What will be printed after executing the following code fragment? p.method(); q.method(); (a) A:0 B:0 (b) A:10 B:20 (c) A:20 B:20 (d) A:10 B:10 (e) A:20 B:10 Question 7 [1 mark] What will be printed after executing the following code fragment? A1 s = new B1(); s.method(); (a) B:20 (b) A:10 (c) A:20 (d) A:10 B:20 (e) B:10 Question 8 [2 marks] What will be printed after executing the following code fragment? System.out.print(((A1)q).x); System.out.print(((B1)q).x); (a) 1020 (b) 2010 (c) 2020 (d) 1010 (e) None of the above
5 VERSION COMPSCI 230 Question 9 [2 marks] What is the result of attempting to compile and run the following statement? ((A1)q).method(); ((B1)q).method(); (a) B:20 B:20 (b) A:10 B:20 (c) A:20 B:10 (d) A:10 B:10 (e) None of the above Question 10 [1.5 marks] Declaring a method final means: (a) it will prepare the object for garbage collection. (b) it cannot be overridden. (c) it cannot be overloaded. (d) it cannot be accessed from outside its class. (e) None of the above Question 11 [1.5 marks] Assigning a subclass reference to a superclass variable is safe: (a) only when the superclass is concrete. (b) only when the superclass is abstract. (c) because the subclass object is an object of its superclass. (d) because the subclass object has an object of its superclass. (e) None of the above Question 12 [1 mark] The default equals implementation of the Object class determines: (a) whether two references have the same type. (b) whether two objects have the same instance variables. (c) whether two objects have the same instance variable values. (d) whether two references refer to the same object in memory. (e) None of the above. Question 13 [1.5 marks] A class that implements an interface but only gives definitions for some of the method headings given in the interface is called a/an: (a) friendly class (b) abstract class (c) concrete class (d) discrete class (e) None of the above.
6 VERSION COMPSCI 230 Question 14 [1.5 marks] Which of the following statements about interfaces is FALSE? (a) An interface describes a set of methods that can be called on an object, not providing concrete implementation for the methods. (b) Once a class implements an interface, all objects of that class have an is-a relationship with the interface type. (c) An interface describes a set of methods that can be called on an object, providing a default implementation for the methods. (d) Interfaces are useful when attempting to assign common functionality to possibly unrelated classes. (e) None of the above Question 15 [1 mark] Which of the following statements is FALSE? (a) Parameterized type ArrayList< Number > is a supertype of ArrayList< Integer >. (b) A wildcard represents an unknown type. (c) ArrayList implements a dynamically resizable, array-like data structure. (d) Because the wildcard in a method s header does not specify a type parameter name, you cannot use it as a type name throughout the method s body. (e) None of the above The following FOUR questions relate to the classes given below: class Car implements Cloneable { private String licenseplate; // e.g. "ABC123" private double maxspeed; // in kilometers per hour public Car(String lp, double max) { licenseplate = lp; maxspeed = max; public static void main(string[] args) throws Exception{ Car c1 = new Car("ABC123", 150.0); Car c2 = new Car("ABC123", 150.0); Car c3 = (Car) c1.clone(); ArrayList<Car> carlist1 = new ArrayList<Car>(); carlist1.add(c1); carlist1.add(c2); ArrayList carlist2 = (ArrayList) carlist1.clone();
7 VERSION COMPSCI 230 Question 16 [1 mark] What will be printed after executing the following code fragment? (Hint: What is the default implementation of the Object.equals() method?) System.out.print(c1 == c2); System.out.print(" "); System.out.print(c1.equals(c2)); (a) false true (b) false false (c) true false (d) true true (e) None of the above. Question 17 [1 mark] What will be printed after executing the following code fragment? System.out.print(c1 == c3); System.out.print(" "); System.out.print(c1.equals(c3)); (a) false true (b) true false (c) true true (d) false false (e) None of the above. Question 18 [1 mark] What will be printed after executing the following code fragment? System.out.print(carList1==carList2); System.out.print(" "); System.out.print(carList1.equals(carList2)); (a) false false (b) true false (c) false true (d) true true (e) None of the above. Question 19 [1 mark] What will be printed after executing the following code fragment? System.out.print(carList1.get(0).equals(carList2.get(0))); System.out.print(" "); System.out.print(carList1.get(0)==carList2.get(0)); (a) true false (b) false false (c) true true (d) false true (e) None of the above.
8 VERSION COMPSCI 230 Question/Answer Sheet ID. SECTION B Answer all questions in this section in the space provided. If you run out of space then please use the Overflow Sheet and indicate in the allotted space that you have used the Overflow Sheet. Question 20: Assignment 1 [16 marks] In assignment 1, you were asked to add several changes to the program which displays moving shapes bouncing off the edges of the window. (a) Complete the MovingSpecialShape class which draws a special square on the animation panel. The square is filled with the fill colour and the border is drawn with the border colour. It also has a red circle which rotates around the circular boundary. Some examples are given below: (p.x, p.y) radius * Math.cos(radian) (cx, cy) radius * Math.sin(radian) radius You are required to calculate the top left corner (rx, ry) of the red circle. The position of the red circle depends on the angle rotated referenced by the centre point (cx, cy) of the shape. The radius of the shape depends on the width/height of the shape. Given the following classes: (rx, ry) import java.awt.*; public abstract class MovingShape { public int marginwidth, marginheight; protected Point p; protected int width, height; protected Color fillcolor; protected MovingPath path; protected 8oolean selected = false; protected Color bordercolor; // the margin of the animation // the top left corner of the shapes // the width and height of the shapes // the fill colour of the shapes // the moving path of the shapes // draw handles if selected // the border colour of the shapes public MovingShape() { this(0, 0, 20, 20, 500, 500, Color.blue, Color.black, 0);
9 VERSION COMPSCI 230 Question/Answer Sheet ID. public MovingShape(int x, int y, int w, int h, int mw, int mh, Color fc, Color bc,int pathtype) { p = new Point(x,y); marginwidth = mw; marginheight = mh; fillcolor = fc; bordercolor = bc; width = w; height = h; setpath (pathtype); public abstract boolean contains(point p); public abstract void draw(graphics g); import java.awt.*; public class MovingRectangle extends MovingShape { public MovingRectangle() { super(); public MovingRectangle(int x, int y, int w, int h, int mw, int mh, Color fc, Color bc, int typeofpath) { super(x,y,w,h,mw,mh,fc,bc, typeofpath); public void draw(graphics g) { Graphics2D g2d = (Graphics2D) g; g.setcolor(fillcolor); g.fillrect(p.x, p.y, width, height); g.setcolor(bordercolor); g.drawrect(p.x, p.y, width, height); drawhandles(g); public boolean contains(point mousept) { return (p.x <= mousept.x && mousept.x <= (p.x + width + 1) && p.y <= mousept.y && mousept.y <= (p.y + height + 1)); import java.awt.*; public class MovingSquare extends MovingRectangle { public MovingSquare() { super(); public MovingSquare(int x, int y, int s, int mw, int mh, Color fc, Color bc, int typeofpath) { super(x,y,s,s,mw,mh,fc,bc, typeofpath); public void setwidth(int w) { super.setwidth(w); super.setheight(w); public void setheight(int h) { super.setwidth(h); super.setheight(h);
10 VERSION COMPSCI 230 Question/Answer Sheet ID. Complete the class MovingSpecialShape below. Do not duplicate code unnecessarily. public class MovingSpecialShape extends { int angle; //2 marks public MovingSpecialShape() { super(); public MovingSpecialShape(int x, int y, int s, int mw, int mh, Color fc, Color bc, int typeofpath) { //2 marks public void { //1 mark super.draw(g); int centerx, centery, x1, y1; int radius = Math.min(width, height)/2 5; double radian = Math.PI * angle/180; //calculate the centre point (cx,cy) //2 marks //calculate the reference point (rx,ry) int dx = (int) (radius * Math.cos(radian)); int dy = (int) (radius * Math.sin(radian)); //2 marks g.setcolor(color.red); g.filloval(x1, y1, 10, 10); //update the angle //1 mark (10 marks)
11 VERSION COMPSCI 230 Question/Answer Sheet ID. (b) Rewrite the FallingPath class using an Anonymous Class public void setpath(int pathid) { switch (pathid) { case MovingPath.ROTATING : { path = new RotatingPath(); break; case MovingPath.FALLING : { path = new FallingPath(); break; public class FallingPath extends MovingPath { private double am = Math.random() * 20, stx =0.5, sindeltax = 0; public FallingPath() { public void move() { sindeltax = sindeltax + stx; p.x = (int) Math.round(p.x + am * Math.sin(sinDeltax)); p.y = p.y + deltay; if (p.y > marginheight) // if it reaches the bottom, restart p.y = 0; public void setpath(int pathid) { switch (pathid) { case MovingPath.ROTATING : { path = new RotatingPath(); break; case MovingPath.FALLING : { path = new { private double ; break; (6 marks)
12 VERSION COMPSCI 230 Question/Answer Sheet ID. Question 21: Generic Methods [8 marks] We would like to write a method which merges two collections/lists of the same type together. Example 1: Merging two integer lists: List<Integer> intlist1 = new ArrayList<Integer>(); intlist1.add(new Integer(1)); intlist1.add(new Integer(2)); System.out.println(intList1); List<Integer> intlist2 = new ArrayList<Integer>(); intlist2.add(new Integer(3)); System.out.println(intList2); merge(intlist1, intlist2); System.out.println(intList1); Output: [1, 2] [3] [1, 2, 3] Example 2: Merging two double lists: List<Double> doublelist1 = new ArrayList<Double>(); doublelist1.add(new Double(1.2)); doublelist1.add(new Double(2.3)); System.out.println(doubleList1); List<Double> doublelist2 = new ArrayList<Double>(); doublelist2.add(new Double(3.4)); System.out.println(doubleList2); merge(doublelist1, doublelist2); System.out.println(doubleList1); Output: [1.2, 2.3] [3.4] [1.2, 2.3, 3.4] Example 3: Merging two String lists: List<String> strlist1 = new ArrayList<String>(); strlist1.add( a ); System.out.println(strList1); List<String> strlist2 = new ArrayList<String>(); strlist1.add( b ); merge(strlist1, strlist2); System.out.println(strList1); [a] [a, b] Here s the first attempt: public static void merge(list<?> c1, List<?> c2) { for (Object o : c2) c1.add(o); However, the above method couldn t be compiled because you cannot just shove objects into a collection of unknown type.
13 VERSION COMPSCI 230 Question/Answer Sheet ID. (a) Rewrite the above method using generic methods. Method declarations can be parameterized by one or more type parameters. public static void merge(, ) { for ( ) c1.add(o); (6 marks) (b) Next, we would like to apply the merge method ONLY on the subclasses of the class Number. public abstract class Number extends Object public final class Integer extends Number public final class Double extends Number public final class Long extends Number Therefore, if you merge two String lists, your program will return a compile time error. List<String> strlist1 = new ArrayList<String>(); merge(strlist1, strlist2); >javac TestMyList.java TestMyList.java:38: <T>merge(java.util.List<T>,java.util.List<T>) in TestMyList cannot be applied to (java.util.list<java.lang.string>,java.util.list<java.lang.string>) merge(strlist1, strlist2); ^ 1 error Complete the new version of the merge method below. public static < > void merge(,... ) { (2 marks)
14 VERSION COMPSCI 230 Question/Answer Sheet ID. Overflow pages please number answers carefully
15 VERSION COMPSCI 230 Question/Answer Sheet ID. Overflow pages please number answers carefully APPENDIX FOLLOWS
16 APPENDIX COMPSCI 230 java.awt class Graphics void setcolor(color) void drawline(int, int, int, int) void drawoval(int, int, int, int) void drawpolygon(int[], int[], int) void drawpolygon(polygon) void drawrect(int, int, int, int) void filloval(int, int, int, int) void fillpolygon(int[], int[], int) void fillpolygon(polygon) void fillrect(int, int, int, int) Class Graphics2D void fill(shape s) void draw(shape s) class Polygon Polygon(int[] xpoints, int[] ypoints, int npoints) boolean contains(point p) boolean contains(int x, int y) Class ArrayList<E> boolean add(e o) void add(int index, E element) APPENDIX
THE UNIVERSITY OF AUCKLAND
THE UNIVERSITY OF AUCKLAND SECOND SEMESTER, 2008 Campus: Tamaki COMPUTER SCIENCE TEST Software Design and Construction (Time allowed: 60 minutes) NOTE: Attempt ALL questions. Write your answers in the
More informationTHE UNIVERSITY OF AUCKLAND
THE UNIVERSITY OF AUCKLAND CompSci 101 FIRST SEMESTER, 2008 Campus: City COMPUTER SCIENCE TEST Principles of Programming (Time allowed: 75 MINUTES) NOTE: Attempt ALL questions Write your answers in the
More informationTHE UNIVERSITY OF AUCKLAND
CompSci 101 with answers THE UNIVERSITY OF AUCKLAND FIRST SEMESTER, 2012 Campus: City COMPUTER SCIENCE Principles of Programming (Time Allowed: TWO hours) NOTE: You must answer all questions in this test.
More informationINSTRUCTIONS TO CANDIDATES
NATIONAL UNIVERSITY OF SINGAPORE SCHOOL OF COMPUTING MIDTERM ASSESSMENT FOR Semester 2 AY2017/2018 CS2030 Programming Methodology II March 2018 Time Allowed 90 Minutes INSTRUCTIONS TO CANDIDATES 1. This
More informationGraphics Applets. By Mr. Dave Clausen
Graphics Applets By Mr. Dave Clausen Applets A Java application is a stand-alone program with a main method (like the ones we've seen so far) A Java applet is a program that is intended to transported
More informationAgenda. Objects and classes Encapsulation and information hiding Documentation Packages
Preliminaries II 1 Agenda Objects and classes Encapsulation and information hiding Documentation Packages Inheritance Polymorphism Implementation of inheritance in Java Abstract classes Interfaces Generics
More informationInstance Members and Static Members
Instance Members and Static Members You may notice that all the members are declared w/o static. These members belong to some specific object. They are called instance members. This implies that these
More informationHAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.
HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all
More informationLecture 7 A First Graphic Program And Data Structures & Drawing
Lecture 7 A First Graphic Program And Data Structures & Drawing Objective The objective is that you will understand: How to program the generation of 2D and 3D images. How to manipulate those images through
More informationCMSC 132: Object-Oriented Programming II
CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation
More informationOutline. Inheritance. Abstract Classes Interfaces. Class Extension Overriding Methods Inheritance and Constructors Polymorphism.
Outline Inheritance Class Extension Overriding Methods Inheritance and Constructors Polymorphism Abstract Classes Interfaces 1 OOP Principles Encapsulation Methods and data are combined in classes Not
More informationGraphics Applets. By Mr. Dave Clausen
Graphics Applets By Mr. Dave Clausen Applets A Java application is a stand-alone program with a main method (like the ones we've seen so far) A Java applet is a program that is intended to transported
More informationCOS226 - Spring 2018 Class Meeting # 13 March 26, 2018 Inheritance & Polymorphism
COS226 - Spring 2018 Class Meeting # 13 March 26, 2018 Inheritance & Polymorphism Ibrahim Albluwi Composition A GuitarString has a RingBuffer. A MarkovModel has a Symbol Table. A Symbol Table has a Binary
More informationHAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.
HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all
More informationINHERITANCE AND OBJECTS. Fundamentals of Computer Science I
INHERITANCE AND OBJECTS Fundamentals of Computer Science I Outline Inheritance Sharing code between related classes Putting similar objects in the same bucket Extremely common in modern OOP languages Managing
More informationBuilding Java Programs
Building Java Programs Chapter 3 Lecture 3-2: Return; doubles and casting reading: 3.2, 4.1 videos: Ch. 3 #2 Copyright 2009 by Pearson Education Finish Car example Lecture outline Returns Java Math library
More informationObject- Oriented Analysis, Design and Programming
Object- Oriented Analysis, Design and Programming Medialogy, Semester 4 Monday 19 April 2010 9.00 12.00 You have 3 hours to complete this examination. Neither written material nor electronic equipment
More informationCS 3331 Advanced Object-Oriented Programming Exam 1
1 Fall 2015 (Thursday, October 22) Name: CS 3331 Advanced Object-Oriented Programming Exam 1 This test has 13 questions and pages numbered 1 through 9. Reminders This test is closed-notes and closed-book.
More informationInheritance and objects
Inheritance and objects CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2014 Inheritance Overview Sharing code between related classes Putting similar objects in the same bucket
More informationSolution Notes. COMP 151: Terms Test
Family Name:.............................. Other Names:............................. ID Number:............................... Signature.................................. Solution Notes COMP 151: Terms
More informationINTRODUCTION TO SOFTWARE SYSTEMS (COMP1110/COMP1140/COMP1510/COMP6710)
Important notice: This document is a sample exam. The final exam will differ from this exam in numerous ways. The purpose of this sample exam is to provide students with access to an exam written in a
More informationObject Orientated Programming in Java. Benjamin Kenwright
Graphics Object Orientated Programming in Java Benjamin Kenwright Outline Essential Graphical Principals JFrame Window (Popup Windows) Extending JFrame Drawing from paintcomponent Drawing images/text/graphics
More informationConstructor. Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.
Constructor Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the best way to design these classes so to avoid redundancy? The
More informationExercise 0.1 (Review from lectures no submission required)
CSCI 2110- Data Structures and Algorithms Laboratory No. 1 Week of September 10, 2018 Due: Saturday, September 15, 2018, 11.55 PM (five minutes to midnight) Review of Object-Oriented Programming Concepts
More informationExample: Count of Points
Example: Count of Points 1 class Point { 2... 3 private static int numofpoints = 0; 4 5 Point() { 6 numofpoints++; 7 } 8 9 Point(int x, int y) { 10 this(); // calling the constructor with no input argument;
More informationOutline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring
Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,
More information1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'
Practice questions: 1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4' 2. Will System.out.println((char)4) display 4? a. Yes b. No 3. The expression "Java
More informationAP CS Unit 6: Inheritance Exercises
AP CS Unit 6: Inheritance Exercises 1. Suppose your program contains two classes: a Student class and a Female class. Which of the following is true? a) Making the Student class a subclass of the Female
More informationCollections, Maps and Generics
Collections API Collections, Maps and Generics You've already used ArrayList for exercises from the previous semester, but ArrayList is just one part of much larger Collections API that Java provides.
More informationPolymorphism: Interfaces and Iteration. Fundamentals of Computer Science
Polymorphism: Interfaces and Iteration Fundamentals of Computer Science Outline A shape object hierarchy Classes that extend Versus classes that implements Java interfaces How Java handles multiple-inheritance
More informationAppendix F: Java Graphics
Appendix F: Java Graphics CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Appendix F: Java Graphics CS 121 1 / 1 Topics Graphics and Images Coordinate
More informationTutorial 8 Date: 15/04/2014
Tutorial 8 Date: 15/04/2014 1. What is wrong with the following interface? public interface SomethingIsWrong void amethod(int avalue) System.out.println("Hi Mom"); 2. Fix the interface in Question 2. 3.
More informationInheritance and objects
Inheritance and objects CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2013 Inheritance Overview Sharing code between related classes Pu8ng similar objects in the same bucket Extremely
More informationCSE 143 Lecture 20. Circle
CSE 143 Lecture 20 Abstract classes Circle public class Circle { private double radius; public Circle(double radius) { this.radius = radius; public double area() { return Math.PI * radius * radius; public
More informationJava Primer. CITS2200 Data Structures and Algorithms. Topic 2
CITS2200 Data Structures and Algorithms Topic 2 Java Primer Review of Java basics Primitive vs Reference Types Classes and Objects Class Hierarchies Interfaces Exceptions Reading: Lambert and Osborne,
More information1B1b Inheritance. Inheritance. Agenda. Subclass and Superclass. Superclass. Generalisation & Specialisation. Shapes and Squares. 1B1b Lecture Slides
1B1b Inheritance Agenda Introduction to inheritance. How Java supports inheritance. Inheritance is a key feature of object-oriented oriented programming. 1 2 Inheritance Models the kind-of or specialisation-of
More informationMidterm Exam 5 April 20, 2015
Midterm Exam 5 April 20, 2015 Name: Section 1: Multiple Choice Questions (24 pts total, 3 pts each) Q1: Which of the following is not a kind of inheritance in C++? a. public. b. private. c. static. d.
More informationCMSC 433 Section 0101 Fall 2012 Midterm Exam #1
Name: CMSC 433 Section 0101 Fall 2012 Midterm Exam #1 Directions: Test is closed book, closed notes. Answer every question; write solutions in spaces provided. Use backs of pages for scratch work. Good
More informationAppendix F: Java Graphics
Appendix F: Java Graphics CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Appendix F: Java Graphics CS 121 1 / 15 Topics Graphics and Images Coordinate
More informationF I N A L E X A M I N A T I O N
Faculty Of Computer Studies M257 Putting Java to Work F I N A L E X A M I N A T I O N Number of Exam Pages: (including this cover sheet( Spring 2011 April 4, 2011 ( 5 ) Time Allowed: ( 1.5 ) Hours Student
More informationInheritance. Inheritance
1 2 1 is a mechanism for enhancing existing classes. It allows to extend the description of an existing class by adding new attributes and new methods. For example: class ColoredRectangle extends Rectangle
More informationCS 113 PRACTICE FINAL
CS 113 PRACTICE FINAL There are 13 questions on this test. The value of each question is: 1-10 multiple choice (4 pt) 11-13 coding problems (20 pt) You may get partial credit for questions 11-13. If you
More informationGraphics -- To be discussed
Graphics -- To be discussed 1 Canvas Class... 1 2 Graphics Class... 1 3 Painting... 1 4 Color Models... 4 5 Animation's Worst Enemy: Flicker... 4 6 Working with Java Images... 5 6.1 Image Loading Chain
More informationObject-Oriented Concepts
JAC444 - Lecture 3 Object-Oriented Concepts Segment 2 Inheritance 1 Classes Segment 2 Inheritance In this segment you will be learning about: Inheritance Overriding Final Methods and Classes Implementing
More informationInheritance and Interfaces
Inheritance and Interfaces Object Orientated Programming in Java Benjamin Kenwright Outline Review What is Inheritance? Why we need Inheritance? Syntax, Formatting,.. What is an Interface? Today s Practical
More informationAP CS Unit 8: Inheritance Exercises
AP CS Unit 8: Inheritance Exercises public class Animal{ System.out.print("A"); public void m2(){ System.out.print("B"); public class Dog extends Animal{ System.out.print("C"); public void m3(){ System.out.print("D");
More informationThe Nervous Shapes Example
The Nervous Shapes Example This Example is taken from Dr. King s Java book 1 11.6 Abstract Classes Some classes are purely artificial, created solely so that subclasses can take advantage of inheritance.
More informationAbstract Class. Lecture 21. Based on Slides of Dr. Norazah Yusof
Abstract Class Lecture 21 Based on Slides of Dr. Norazah Yusof 1 Abstract Class Abstract class is a class with one or more abstract methods. The abstract method Method signature without implementation
More informationCOMP 250. inheritance (cont.) interfaces abstract classes
COMP 250 Lecture 31 inheritance (cont.) interfaces abstract classes Nov. 20, 2017 1 https//goo.gl/forms/ymqdaeilt7vxpnzs2 2 class Object boolean equals( Object ) int hashcode( ) String tostring( ) Object
More informationCOMP1008 An overview of Polymorphism, Types, Interfaces and Generics
COMP1008 An overview of Polymorphism, Types, Interfaces and Generics Being Object-Oriented Exploiting the combination of: objects classes encapsulation inheritance dynamic binding polymorphism pluggability
More informationPrelim 1. CS 2110, October 1, 2015, 5:30 PM Total Question Name True Short Testing Strings Recursion
Prelim 1 CS 2110, October 1, 2015, 5:30 PM 0 1 2 3 4 5 Total Question Name True Short Testing Strings Recursion False Answer Max 1 20 36 16 15 12 100 Score Grader The exam is closed book and closed notes.
More informationCSE 331 Summer 2017 Final Exam. The exam is closed book and closed electronics. One page of notes is allowed.
Name Solution The exam is closed book and closed electronics. One page of notes is allowed. The exam has 6 regular problems and 1 bonus problem. Only the regular problems will count toward your final exam
More informationChapter 11 Inheritance and Polymorphism
Chapter 11 Inheritance and Polymorphism 1 Motivations OOP is built on three principles: Encapsulation (classes/objects, discussed in chapters 9 and 10), Inheritance, and Polymorphism. Inheritance: Suppose
More informationI pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.
Name: Covers Chapters 1-3 50 mins CSCI 1301 Introduction to Programming Armstrong Atlantic State University Instructor: Dr. Y. Daniel Liang I pledge by honor that I will not discuss this exam with anyone
More informationInheritance (cont.) Inheritance. Hierarchy of Classes. Inheritance (cont.)
Inheritance Inheritance (cont.) Object oriented systems allow new classes to be defined in terms of a previously defined class. All variables and methods of the previously defined class, called superclass,
More informationMidterm Exam CS 251, Intermediate Programming March 12, 2014
Midterm Exam CS 251, Intermediate Programming March 12, 2014 Name: NetID: Answer all questions in the space provided. Write clearly and legibly, you will not get credit for illegible or incomprehensible
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 20, 2014 Abstract
More informationAP CS Unit 7: Interfaces Exercises Assume all code compiles unless otherwise suggested.
AP CS Unit 7: Interfaces Exercises Assume all code compiles unless otherwise suggested. 1. The Nose class... b) will not compile because the m1 method parameter should be named n, not x. 2. The Ears class...
More informationLecture Outline. Parametric Polymorphism and Java Generics. Polymorphism. Polymorphism
Lecture Outline Parametric Polymorphism and Java Generics Parametric polymorphism Java generics Declaring and instantiating generics Bounded types: restricting instantiations Generics and subtyping. Wildcards
More informationICS 4U. Introduction to Programming in Java. Chapter 10 Notes
ICS 4U Introduction to Programming in Java Chapter 10 Notes Classes and Inheritance In Java all programs are classes, but not all classes are programs. A standalone application is a class that contains
More informationPerson class. A class can be derived from an existing class by using the form
Person class //Person.java - characteristics common to all people class Person { Person(String name) { this.name = name; void setage(int age) { this.age = age; void setgender(gender gender) { this.gender
More informationFirst IS-A Relationship: Inheritance
First IS-A Relationship: Inheritance The relationships among Java classes form class hierarchy. We can define new classes by inheriting commonly used states and behaviors from predefined classes. A class
More informationCIS 110 Introduction To Computer Programming. October 5th, 2011 Exam 1. Review problems
CIS 110 Introduction To Computer Programming October 5th, 2011 Exam 1 Review problems Scores: 1 2 3 4 5 6 Total (100 max) CIS 110 Exam 1 Instructions You have 50 minutes to finish this exam. Time will
More informationThis exam is closed textbook(s) and closed notes. Use of any electronic device (e.g., for computing and/or communicating) is NOT permitted.
York University AS/AK/ITEC 2610 3.0 All Sections OBJECT-ORIENTED PROGRAMMING Midterm Test Duration: 90 Minutes This exam is closed textbook(s) and closed notes. Use of any electronic device (e.g., for
More informationObject-Oriented Programming Concepts
Object-Oriented Programming Concepts Object-oriented programming מונחה עצמים) (תכנות involves programming using objects An object ) represents (עצם an entity in the real world that can be distinctly identified
More informationIslamic University of Gaza Faculty of Engineering Computer Engineering Department
Student Mark Islamic University of Gaza Faculty of Engineering Computer Engineering Department Question # 1 / 18 Question # / 1 Total ( 0 ) Student Information ID Name Answer keys Sector A B C D E A B
More informationTopic 9 More Graphics. Based on slides bu Marty Stepp and Stuart Reges from
Topic 9 More Graphics Based on slides bu Marty Stepp and Stuart Reges from http://www.buildingjavaprograms.com/ Clicker Question What happens if a graphics object is used to draw a shape that exceeds the
More informationMidterm Exam CS 251, Intermediate Programming October 8, 2014
Midterm Exam CS 251, Intermediate Programming October 8, 2014 Name: NetID: Answer all questions in the space provided. Write clearly and legibly, you will not get credit for illegible or incomprehensible
More informationCS1150 Principles of Computer Science Objects and Classes
CS1150 Principles of Computer Science Objects and Classes Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Colorado Springs Object-Oriented Thinking Chapters 1-8
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 21, 2013 Abstract
More informationCSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2015
CSCI 136 Written Exam #0 Fundamentals of Computer Science II Spring 2015 Name: This exam consists of 6 problems on the following 7 pages. You may use your single-sided handwritten 8 ½ x 11 note sheet during
More informationPractice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course
: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course 1. Given the following hierarchy: class Alpha {... class Beta extends Alpha {... class Gamma extends Beta {... In what order
More informationFall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.
Grading Page 1 / 4 Page3 / 20 Page 4 / 13 Page 5 / 10 Page 6 / 26 Page 7 / 17 Page 8 / 10 Total / 100 1. (4 points) What is your course section? CS 101 CS 101E Pledged Page 1 of 8 Pledged The following
More information01. Which of the following statement describes dynamic resizing as is applies to the ArrayList class?
Exposure Java Chapter 11 Multiple Choice Test ArrayList Class DO NOT WRITE ON THIS TEST This test includes program segments, which are not complete programs. Answer such questions with the assumption that
More information1.Which four options describe the correct default values for array elements of the types indicated?
1.Which four options describe the correct default values for array elements of the types indicated? 1. int -> 0 2. String -> "null" 3. Dog -> null 4. char -> '\u0000' 5. float -> 0.0f 6. boolean -> true
More information8359 Object-oriented Programming with Java, Part 2. Stephen Pipes IBM Hursley Park Labs, United Kingdom
8359 Object-oriented Programming with Java, Part 2 Stephen Pipes IBM Hursley Park Labs, United Kingdom Dallas 2003 Intro to Java recap Classes are like user-defined types Objects are like variables of
More informationCH. 2 OBJECT-ORIENTED PROGRAMMING
CH. 2 OBJECT-ORIENTED PROGRAMMING ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN JAVA, GOODRICH, TAMASSIA AND GOLDWASSER (WILEY 2016) OBJECT-ORIENTED
More informationProgramming 2. Inheritance & Polymorphism
Programming 2 Inheritance & Polymorphism Motivation Lame Shape Application public class LameShapeApplication { Rectangle[] therects=new Rectangle[100]; Circle[] thecircles=new Circle[100]; Triangle[] thetriangles=new
More informationCS 112 Programming 2. Lecture 06. Inheritance & Polymorphism (1) Chapter 11 Inheritance and Polymorphism
CS 112 Programming 2 Lecture 06 Inheritance & Polymorphism (1) Chapter 11 Inheritance and Polymorphism rights reserved. 2 Motivation Suppose you want to define classes to model circles, rectangles, and
More informationPowerPoint Slides. Object-Oriented Design Using JAVA. Chapter 2. by Dale Skrien
PowerPoint Slides Object-Oriented Design Using JAVA by Dale Skrien Chapter 2 Object-oriented Programming Divides the program into a set of communicating objects Encapsulates in an object all the behavior
More informationEXAMINATIONS 2012 MID-YEAR SWEN221. Software Development. Question Topic Marks. 1. Debugging and Exceptions 20
T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:..................... EXAMINATIONS 2012 MID-YEAR SWEN221 Software Development Time
More informationExercise: Singleton 1
Exercise: Singleton 1 In some situations, you may create the only instance of the class. 1 class mysingleton { 2 3 // Will be ready as soon as the class is loaded. 4 private static mysingleton Instance
More informationCOMP200 ABSTRACT CLASSES. OOP using Java, from slides by Shayan Javed
1 1 COMP200 ABSTRACT CLASSES OOP using Java, from slides by Shayan Javed Abstract Classes 2 3 From the previous lecture: public class GeometricObject { protected String Color; protected String name; protected
More informationCSC 1051 Algorithms and Data Structures I. Midterm Examination October 9, Name: KEY
CSC 1051 Algorithms and Data Structures I Midterm Examination October 9, 2014 Name: KEY Question Value Score 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 10 TOTAL 100 Please answer questions in the
More informationNATIONAL UNIVERSITY OF SINGAPORE
NATIONAL UNIVERSITY OF SINGAPORE SCHOOL OF COMPUTING TERM TEST #1 Semester 1 AY2006/2007 CS1101X/Y/Z PROGRAMMING METHODOLOGY 16 September 2006 Time Allowed: 60 Minutes INSTRUCTIONS 1. This question paper
More informationFull file at Chapter 2 - Inheritance and Exception Handling
Chapter 2 - Inheritance and Exception Handling TRUE/FALSE 1. The superclass inherits all its properties from the subclass. ANS: F PTS: 1 REF: 76 2. Private members of a superclass can be accessed by a
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 12 Thomas Wies New York University Review Last lecture Modules Outline Classes Encapsulation and Inheritance Initialization and Finalization Dynamic
More informationUse the scantron sheet to enter the answer to questions (pages 1-6)
Use the scantron sheet to enter the answer to questions 1-100 (pages 1-6) Part I. Mark A for True, B for false. (1 point each) 1. Abstraction allow us to specify an object regardless of how the object
More information1.1. Annotations History Lesson - C/C++
1. Additions Thanks to Dr. James Heliotis. He started it all :) See also here: and see also here: and here: You need to use the tools from the Java release candidate 1 % bash % export PATH=/usr/local/j2sdk1.5.0-rc1/bin:$PATH
More informationCS163/164 Final Exam Study Session
CS163/164 Final Exam Study Session Review What is printed? public static void main (String [] args){ String s = "Winter Break"; System.out.println(s.indexOf('c')); System.out.println(s.indexOf('e')); System.out.println(s.charAt(2));
More informationInterfaces and itera-on. CSCI 136: Fundamentals of Computer Science II Keith Vertanen
Interfaces and itera-on CSCI 136: Fundamentals of Computer Science II Keith Vertanen Overview A shape object hierarchy Classes that extend Versus classes that implements Java interfaces How Java handles
More informationMore Relationships Between Classes
More Relationships Between Classes Inheritance: passing down states and behaviors from the parents to their children Interfaces: grouping the methods, which belongs to some classes, as an interface to
More informationCS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.
Name CS 110 Practice Final Exam originally from Winter, 2003 Instructions: closed books, closed notes, open minds, 3 hour time limit. There are 4 sections for a total of 49 points. Part I: Basic Concepts,
More informationCS-202 Introduction to Object Oriented Programming
CS-202 Introduction to Object Oriented Programming California State University, Los Angeles Computer Science Department Lecture III Inheritance and Polymorphism Introduction to Inheritance Introduction
More informationChapter 10 Inheritance and Polymorphism. Dr. Hikmat Jaber
Chapter 10 Inheritance and Polymorphism Dr. Hikmat Jaber 1 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the
More informationExamination Questions Midterm 1
CS1102s Data Structures and Algorithms 10/2/2010 Examination Questions Midterm 1 This examination question booklet has 9 pages, including this cover page, and contains 15 questions. You have 40 minutes
More informationPractice for Chapter 11
Practice for Chapter 11 MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Object-oriented programming allows you to derive new classes from existing
More informationpublic static boolean isoutside(int min, int max, int value)
See the 2 APIs attached at the end of this worksheet. 1. Methods: Javadoc Complete the Javadoc comments for the following two methods from the API: (a) / @param @param @param @return @pre. / public static
More informationCIS 110 Introduction To Computer Programming. October 5th, 2011 Exam 1. Answer key for review problems
CIS 110 Introduction To Computer Programming October 5th, 2011 Exam 1 Answer key for review problems Scores: 1 2 3 4 5 6 Total (100 max) CIS 110 Exam 1 Instructions You have 50 minutes to finish this exam.
More informationUniversity of Cape Town Department of Computer Science. Computer Science CSC115F
University of Cape Town Department of Computer Science Computer Science CSC115F June 2003 Final Exam Answer all questions. All questions that refer to elements of programming make reference to the Java
More information