public void m1(){ int n = 5; m2( n ); System.out.println( n ); }

Size: px
Start display at page:

Download "public void m1(){ int n = 5; m2( n ); System.out.println( n ); }"

Transcription

1 Review The Dog class will be used as needed. public class Dog { private int x; public Dog(int h){ x = h; public void set(int n){ x = n; public int get(){ return x; public String tostring(){ return "woof"; Arguments and Parameters. Note. What we have called parameters are also called formal parameters and arguments are sometimes called actual parameters. 1. If the parameter is a primitive data type, then changing the parameter has no effect on the argument. What is displayed? 5 2. If the parameter is an object type, and the reference is not changed, then the method can change the object. What is displayed? 4 3. What is displayed? 3 public void m1(){ int n = 5; m2( n ); System.out.println( n ); public void m2( int k ){ k = 20; public void m3(){ Dog gone = new Dog( 3 ); m4( gone ); System.out.println( gone.get() ); public void m4( Dog gee ){ gee.set( 4 ); mutator method public void m5(){ Dog gone = new Dog( 3 ); m6( gone ); System.out.println( gone.get() ); n k gone gee gone public void m6( Dog gee ){ gee = new Dog( 5 ); gee.set( 6 ); gee

2 4. What is displayed? big 5. What is displayed? What is displayed? What is displayed? Yes? public void m5(){ String a = "big"; m6( a ); System.out.println( a ); public void m6( String str ){ str = str + " toe"; public void m5(){ int [] a = {7, 6, 5 ; m6( a ); for ( int x : a ) System.out.print( x + " "); public void m6( int [] b ){ b[0] = 11; public void m5(){ int [] a = {7, 6, 5 ; m6( a ); for ( int x : a ) System.out.print( x + " "); public void m6( int [] b ){ b[0] = 2; b = new int[2]; b[0] = 14; b[1] = 23; public void m7(){ String x = "Yes"; x = m8( x ); System.out.println( x ); public String m8( String str ){ str = str + "?"; return str; a str a b a b x str Generating Random Integers (int)( num * Math.random() ) + min where num = max - min Which expression generates a full range of valid indices of the array? C int [] a = new int[ some positive value ]; a) int index = (int)( (a.length-1)*math.random() ) + 1; b) int index = (int)( a.length*math.random() ) + 1; c) int index = (int)( a.length*math.random() ); d) int index = (int)( (a.length-1)*math.random() ); e) none of the above

3 oolean Expressions Order of Operations! highest precedence && middlest lowest!p!q DeMorgan s Laws!( p && q ) is equivalent to!p &&!q!( p q ) is equivalent to Truth Tables can be useful way of organizing all the combinations A expression True True True False False True False False D 9) Assume that a and b are integers. The boolean expression!(a <= b) && ( a*b > 0 ) will always evaluate to true given that a) a = b b) a > b c) a < b d) a > b and b > 0 e) a > b and b < 0 A 10) Given that a, b, and c are integers, consider the boolean expression (a < b)!( (c == a*b) && (c < a) ) Which of the following will guarantee that the expression is true? a) c < a is false b) c < a is true c) a < b is false d) c == a * b is true e) c == a * b is true, and c < a is true 11) If c and d are boolean variables, which one of the answer choices is NOT equivalent to the following expression? ( c && d )!= ( c d ) a) ( c &&!d ) (!c && d ) b) ( c d ) && (!c &&!d ) c) ( c d ) && (!c!d ) d) ( c d ) &&!( c && d ) e) c!= d 12) Specify the range of values of x and y that make this expression true. This is true for all values of x and y!( x > 10 && y > 20 )!(x <= 0 && y <= 5)

4 Enhanced For Loops. These are good for traversing an array or array list. Do NOT use if you need to compare adjacent elements or change the contents of an array or array list. for ( Data_Type_of_Each_Element var_name : collection ) { collection is an array, list, or array list The first time through the loop var_name is the element at index 0. The next time it is the element at index 1 and so on. D 13. What is displayed? int [] h = {9, 3, 7; for ( int v : h ) System.out.print( v + " " ); 14. Select the TRUE statement. a) This does not compile. b) This compiles but throws an index out of bounds exception. c) This displays d) This displays Write the missing code so the get method is called for each element of the array. Dog emma : cuties 16. Write the missing code so the get method is called for each element of the list. Dog emma : a int [] h = {1, 2, 0 ; for ( int v : h ) System.out.print( h[v] + " " ); Dog [] cuties = new Dog[ 5 ]; // Dog objects are assigned to the array for ( /* missing code */ ) System.out.println(emma.get()); List<Dog> a = new ArrayList<Dog>(); // Dog objects are added to the list for ( /* missing code */ ) System.out.println(emma.get()); Two Dimensional Arrays. A 2D array is an array of arrays. int [][] a = { { 5, 6, 7, { 4, 3, 2 ; a 17. What is the value of a.length? 18. What is the value of a[1].length? 19. What is the row index of a[ 1 ][ 0 ]? 20. What is the column index of a[ 0 ][ 1 ]? What is the contents of the array after the code is executed? int [][] a = { { 5, 6, 7, { 4, 3, 2 ; for ( int b = 0; b < a.length; b++ ){ for ( int c = 0; c < a.length; c++ ){ a[b][c] = a[c][b];

5 A 22. A WordSearch object consists of a 2D array of single characters. Complete the getdown method so that it returns a string that consists of the letters starting at (row, column) going down to and including (row+num-1, column). A precondition is that row and col are valid indices for the array. However, if num is too big and the end point is not a valid location in the array, then the method should return null. 23. Integer.MAX_VALUE is a: a) public class constant b) public instance constant c) public class method d) public instance method 24. If the array contains: what does the method return? -2 public class WordSearch{ private String [][] ltrs; public WordSearch(){ // creates a 2d array of single character strings // precondition: row and col are valid indices in the array public String getdown( int row, int col, int num ){ if ( row + num -1 >= ltrs.length ) return null; String x = ""; for ( int R = row; R < row + num; R++ ) x += ltrs[ R ][ col ]; return x; public int get5( int[][] a ){ int m = Integer.MAX_VALUE; for ( int r = 0; r < a.length; r++ ){ int b = 0; for ( int c = 0; c < a[r].length; c++ ) b += a[r][c]; if ( b < m ) m = b; return m; 25. If the array contains: what does the method return? public int get6( int[][] a ){ int m = Integer.MIN_VALUE; for ( int c = 0; c < a[0].length; c++ ){ int b = 0; for ( int r = 0; r < a.length; r++ ){ b += a[r][c]; 14 if ( b > m ) m = b; return m;

6 Enhanced For Loops and 2D Arrays. The important thing is to remember is that a 2D array is an array of arrays. int [][] a = { { 5, 6, 7, { 4, 3, 2 ; a For example, suppose we want to print the contents of the entire 2D array using enhanced for loops. The outer loop is used to traverse the array that a refers to. The inner loop traverses each of the arrays that are referenced by the outer loop. for ( x : a ) { int [] int for ( y : ) { System.out.print( y ); System.out.println(); 26. What is displayed? int [][] z = { { 9, 11, {3, 5, {7, 1 ; for ( int [] r : z ){ System.out.print( r.length + " " ); 27. Write the missing code so that the code prints int [][] z = { { 9, 11, 2, {4, 3, 5, {7, 1, 6 ; all the elements of the 2D array. for ( int k = 0; k < 3; k++ ){ for ( /* missing code */ ){ System.out.print( num + " " ); int num : z[ k ] System.out.println(); 28. Write the missing code so that the code prints all the elements of the 2D array. int i = 0; i < g.length; i Given an example of a 3 x 3 array that causes this method to return true. Your solution should NOT contain any duplicate values.* int [][] z = { { 9, 11, 2, {4, 3, 5, {7, 1, 6 ; for ( int [] g : z ){ for ( /* missing code */ ){ System.out.print( g[i] + " " ); System.out.println(); public static boolean check( int[][] a ){ for ( int c = 0; c < a[0].length; c++ ){ for ( int r = 1; r < a.length; r++ ){ if ( a[r-1][c] + 1!= a[r][c] ) return false; return true; The complete set of actual solutions does include duplicates. ut your solution should not. Each column should have increasing, sequential numbers x

7 E 30. Select the TRUE statement(s). a) This does not compile because of line 1 b) This does not compile because of line 2 c) This does not compile because of line 3 d) This does not compile because of line 4 e) Compiles but throws a run time exception Dog [][] d = new Dog[3][3]; for ( Dog [] a : d ){ for ( Dog b : a ){ System.out.println( b.get() ); A precondition of the getter method is that row >= 0 && row < a.length 31. What is the missing code so that the getter method correctly iterates through all the Dog objects in the specified row? public class DogChess{ private Dog [][] a = new Dog[8][8]; public DogChess(){ // some array elements are initialized // some elements are null Dog asta : a[ row ] public int getter(int row) { int sum = 0; for ( /* missing code */ ){ if ( asta!= null ) sum += asta.get(); return sum; Inheritance. Use the keyword extends to indicate that a class is a subclass of another A class should only extend another class if the subclass is a member of the super class (always). E.g. the Student class could be a subclass of the Human class because every Student is a Human. On the other hand, the Human class should NOT be a subclass of Student because not every Human is a Student. private instance variables and private methods in the super class cannot be accessed by the subclass. The absolute first thing a subclass constructor must do is call a constructor of its super class. Call the superclass s constructor like this: super( arguments ); If the superclass has a constructor with no parameters, then this constructor will be implicitly called unless you explicitly call a different constructor. is a very useful annotation, it is not testable and you will not see it on the exam. 32. What class s constructor is being called on line 4? 1 2 the Object class 3 4 public class Fish{ private int x; public Fish(int y){ super(); x = y;

8 public class House { private int distance; // from beach private int rooms; public House( int x ){ distance = x; rooms = // hidden public int rooms(){ return rooms; public int distance(){ return distance; 34. What does the code below display? oat b = new Yacht(); System.out.println( b.get() ); Yacht y = new Yacht(); System.out.println( y.get() ); Write the eachhouse class which is a subclass of House. All each House objects are right on the beach so their distance from the beach is zero. Override the rooms method so that it returns twice the number of rooms as a regular House. public class public class oat{ private int x; public oat(){ x = 6; eachhouse extends House{ public eachhouse(){ super( 0 ); public int rooms(){ return 2*super.rooms(); public int get(){ return 3*x; public class Yacht extends oat{ private int x; public Yacht(){ x = 11; 35. What does the code below display? public class Run { public static void main( String [] args ) { met( new Hockey() ); System.out.println(); met( new Sport() ); public static void met( Sport x ){ x.m1(); 36. Why must the method met be a static method? CA A because it is called from a static method public class Sport{ public void m1() { m2(); System.out.print("A"); public void m2() { System.out.print(""); public class Hockey extends Sport{ public void m2() { System.out.print("C"); public void m3() { System.out.print("D"); m1();

9 public class Mammal { public Mammal(){ System.out.print( "M" ); public class Human extends Mammal { public Human(){ System.out.print( "H" ); E A public void m1(){ System.out.print( "A" ); m2(); public void m2(){ System.out.print( "" ); The Mammal and Human classes compile and run. 37. Select the true statement. a) Does not compile. b) Compiles but throws a run-time exception. c) Displays: HA d) Displays: HAD e) none of the above 38. Select the true statement. a) Does not compile. b) Compiles but throws a run-time exception. c) Displays: HE d) Displays: MHE e) Displays: HME public void m2(){ System.out.print( "D" ); public void m3(){ super.m2(); System.out.print( "E" ); Mammal a = new Human(); a.m1(); Actually displays MHAD Mammal a = new Human(); a.m3(); m3 is not a Mammal method Recursion. Identify what the base case (i.e. under what circumstances does the method NOT call itself) Notice how each recursive call leads (eventually) to the base case. If it does not, then the method will generate a run-time exception. 39. What does r( 123 ) cause to be printed? public static void r( int x ){ if ( x <= 0 ) return; 123 r( x / 10 ); System.out.print( x % 10 ); 40. What does r( 456 ) cause to be printed? public static void r( int x ){ if ( x <= 0 ) return; 654 System.out.print( x % 10 ); r( x / 10 );

10 41. What does the following display? String [] a = { "k", "f", "i", "w", "s" ; System.out.println( m2( a, 0 ) ); "f" which is the least string 42. What does the following display? String [] b = {"gone","gown","gopher","got"; System.out.println( m2( b, 1 ) ); "gopher" which is the least string starting from index If s is 1234, what is printed? If s is abcdefgh, what is printed? public String m2( String [] a, int n ){ if ( n == a.length - 1 ) return a[ n ]; String x = a[n]; String y = m2( a, n+ 1 ); if ( x.compareto( y ) < 0 ) return x; else return y; public void m1( String s ){ if ( s.length() == 1 ){ System.out.print( s ); return; hgfedcba int x = s.length() / 2; m1( s.substring( x ) ); m1( s.substring( 0, x ) ); Overloading and Overriding. The term polymorphism refers to the situation where two methods have the same name but different behavior. Compile time polymorphism means two methods (with identical names) have different parameters and can be distinguished at compile time. Runtime polymorphism means the JVM determines which method to call based on the object reference. If two methods have the same name but different parameters types or different number of parameters, then the two methods are overloaded. If a superclass has a method and subclass writes a new method with the same header, then the method in the subclass overrides the method in the superclass. D 45. Select the TRUE statement a) The grunt method is overloaded. b) The grunt method is overridden. c) The grunt method is both overloaded and over ridden. d) There is a compiler error. Two methods, in the same class, cannot differ only by their return types. public class Ape { public void grunt(){ System.out.println( "RAWR" ); public String grunt(){ return "RAWR"; C 46. Given a method with this header: public int mummy( double x ) which of the following headers does NOT overload the method. All methods are in the same class. a) public int mummy( int a ) b) public int mummy( double x, double y ) c) public int mummy( double latte ) d) public int mummy()

11 Interfaces. An interface defines a set of behaviors (i.e. methods). If a class implements an interface, it must then support those behaviors. For example, because ArrayList implements the List interface, we know that it has a certain set of methods and acts in a certain way. LinkedList is a different class that also implements the List interface. This class also behaves like a List. The difference between ArrayList and LinkedList is in how they implement the List interface. One can be more efficient than the other depending on how the List is being used. Another example. If a class implements MouseListener then you know it must have five methods for responding to different mouse events (pressed, released, clicked, entered, exited). Here is an example of a simple interface. public interface Fun{ public void laugh(); public boolean smiling(); Here is a class that implements it. public class APCS implements Fun{ // instance variables // constructors and other methods public void laugh(){ System.out.println( "haha" ); public boolean smiling(){ if ( grade >= personal_goal ) return true; else return false; // instance variables Here are some details to remember. The methods in an interface are considered abstract because they have no body (though the keyword abstract is not used). An interface cannot have instance variables or constructors All methods in an interface are public The implementing class must implement all the methods of the interface.

12 Abstract Classes. An abstract class is used as a class to create subclasses from. For example, java has an abstract class called: RectangularShape To quote from the API RectangularShape is the base class for a number of Shape objects whose geometry is defined by a rectangular frame. Some of its methods are: getcenterx, getcentery, getwidth and getheight. RectangularShape is then extended by four subclasses: Arc2D, Ellipse2D, Rectangle2D, and RoundRectangle2D. It turns out that these four classes are also abstract but they have concrete subclasses. Here s an example. Imagine you are writing a game that is played on a checkerboard. There are many types of pieces on the board. One of them is a Mine (the thing that explodes when you step on it, not the thing that singing dwarves work in). A Mine object does not move (anyone know Stratego?). public abstract class Piece { private int row, col; public Piece( int r, int c ) { row = r; col = c; // attempt to move to this location // returns true if successful // otherwise returns false public abstract boolean move( int r, int c ); public class Mine extends Piece{ public Mine(int r, int c){ super( r, c ); public boolean move( int r, int c ){ return false; // other methods // returns true if this piece is adjacent to p // otherwise returns false public boolean nextto( Piece p ){ int diff1 = Math.abs( this.row - p.row ); int diff2 = Math.abs( this.col - p.col ); return diff1 <= 1 && diff2 <= 1; The Piece is class is abstract so that it can contain data and behaviors shared by closely related classes. ut it is abstract to force users to write subclasses of it. Here are some details to remember. An abstract class may have instance variables and/or constructors An abstract class may or may not have abstract methods (with the keyword abstract) An abstract class may have private methods. In general, think of an abstract class as a regular class except (1) you cannot instantiate an abstract method and (2) if the abstract class has abstract methods, a concrete subclass must implement those methods.

13 A E A 47. Select the TRUE statement(s) - there may be more than one. a) This code compiles. b) This code will not compile because an abstract class cannot have an instance variable. c) This code will not compile because an abstract class cannot have a constructor. d) This code will not compile because an abstract class cannot have a method that includes actual code. e) Regardless of whether it compiles or not, any concrete subclass must override/implement the cast method. 48. Given the below code, what is displayed? Art a = new Music(); a.metc(); 49. If the first line of above code was changed to Music a = new Music(); a) something different would be displayed. b) the same thing would be displayed. 50. Art b = new Music(); b.met(); Select the TRUE statement a) This does not compile because met is abstract b) It compiles and displays 51. Art c = new Art(); c.metc(); Select the TRUE statement a) The first line does not compile b) oth lines cause compiler errors. c) It compiles and displays C 52. Art d = new Music(); d.meta(); This displays a) ACAA b) ACCAA c) AAAC d) AAACC CC public abstract class Magic { private int a; public Magic( int b ){ a = b; public int get(){ return a; public abstract void cast(); public abstract class Art{ public void meta(){ System.out.print("A"); met(); metc(); public abstract void met(); public void metc(){ System.out.print("C"); public class Music extends Art{ public void meta(){ super.meta(); System.out.print("AA"); public void met(){ System.out.print(""); public void metc(){ System.out.print("CC");

14 53. If Fork is an abstract class then Fancy must be a concrete subclass of Fork. 54. Fork may be an interface. True True False False Fork [] x = new Fork[2]; x[0] = new Fancy(); x[1] = new Plain(); 55. Plain may be an interface. True False 56. Fancy may be an abstract class. True False 57. Select the TRUE statement. a) If this code compiles then the Mascot interface must have exactly two methods. b) If this code compiles then the Mascot interface may have one or two methods. c) This class cannot compile because neither method contains any implementing code. public class Goat implements Mascot{ public void m1() { public void m2() { Miscellaneous Questions/Topics. A 58. In the space below show how to call this method from some client code in another class. Set the rows to 2 and the cols to 3. int[][] a = Num1.get(2,3); 59. What does the array contain? Write it so it is obvious what the row and column is for each value If the array contains the following values: then the method a) returns 3 b) returns 1 c) returns 4 d) returns 2 e) throws an index out of bound exception public class Num1{ public static int[][] get( int rows, int cols ){ int [][] a = new int[ rows ][ cols ]; for ( int r = 0; r < a.length; r++ ){ for ( int c = 0; c < a[r].length; c++ ) a[r][c] = r + rows*c; return a; public int get2( int[][] a ){ int i = 0; int num = a.length * a[0].length; while ( i < num ){ int k = i / a[0].length; int j = i % a[0].length; if ( a[ k ][ j ] % 3 == 0 ) return i; i++; return i;

15 E 61. Which of the following statements must be true when the loop exits? a) (width > 0) && (height / width > 5) b) (width == 0) && (height / width > 5) c) (width <= 0) && (height / width <= 5) d) (width == 0) (height / width <= 5) e) (width <= 0) (height / width <= 5) 62. If the array contains the following: { 5, 8, 2, 6, 9, 1, 4 then what does this method return? Consider the following instance variable and method. int width, height; // width is assigned some positive value // height is some value greater than width while((width > 0) && (height / width > 5)){ height -= width; width -= 2; public int get3( int [] a ){ int m = a[0]; for ( int i = 1; i < a.length; i++ ){ if ( a[i] > a[i-1] ) m = a[i]; return m; Common mistake for finding min or max private double[] list; public int getit(double value) { int k = 0; while(k < list.length && list[k]!= value) k++; if(k < list.length) return k; else return -1; Which of the following best describes what is returned by this method? C a) The number of times that value occurs in list, or -1 if all items in the list equal value. b) The number of items in list that are not equal to value, or -1 if value is not in list. c) The index of the first occurrence of value in list, or -1 if value is not in list d) The index of the last occurrence of value in list, or -1 if value is not in list e) The index of the first item in list that is not equal to value, or -1 if value is not in list D 64. This method returns true if a) the array elements are in decreasing order b) the array elements are in increasing order c) the array elements are in non-decreasing order d) the array elements are in non-increasing order public boolean get4( int [] a ){ for ( int i = 1; i < a.length; i++ ){ if ( a[i-1] < a[i] ) return false; return true;

16 65. The following code compiles, runs, and displays no. Explain. Mathematical operations with doubles can result in small, unavoidable errors known as floating-point errors. double x = 1.7; double y = 1.9; if ( x + y == 3.6 ) System.out.println( "yes" ); else System.out.println( "no" ); 66. What is displayed? public static void main(string[] args) { int [] b = { 8, 4, 6, 9, 5 ; m7( b ); for ( int i : b ) System.out.print( i + " " ); public static void m7( int [] a ){ for ( int i = 0; i < a.length-1; i++ ){ int num = i+1; for ( int j = i; j < a.length; j++ ){ if ( a[j] < a[num] ) num = j; if ( a[i] > a[num] ){ int temp = a[i]; a[i] = a[num]; a[num] = temp; D A 67. The code segment is intended to sum the first 10 positive odd integers. Which of the following best describes the error, if any, in this code. a) The segment works as intended. b) The segment sums the first 9 odd integers c) The segment sums the first 20 odd integers d) The segment leaves out the first odd integer and includes the eleventh odd integer in the sum. e) The variable sum is incorrectly initialized. The segment would work as intended if sum were initialized to Select the TRUE statement. a) 23, 11 b) 11, 23 c) 23, 23 d) 11, 11 sum = 0; for(int k = 1; k <= 10; k++){ sum += 2*k + 1; public static void main(string[] args) { int x = 23; int y = 11; m7( x, y ); System.out.println( x + ", " + y ); public static void m7( int a, int b ){ int temp = a; a = b; b = temp;

17 69. What is printed? List<String> z = new ArrayList<String>(); z.add("f"); I S T z.add("i"); z.add("r"); z.add("s"); z.add("t"); z.remove(0); z.remove(1); for ( String s : z ) System.out.println( s ); 70. What is displayed? public static void main(string[] args) { int [] a = { 1, 2, 3 ; int [] b = { 4, 5, 6 ; m1( a ); m2( b ); System.out.println( a[0] + ", " + b[0] ); 1, 8 public static void m1( int [] a ){ a = new int[3]; a[0] = 8; public static void m2( int [] b ){ b[0] = 8; Write 43 in base Write 99 in hexadecimal. 73. Write in base Write 2EA 16 in base 10. E 75. The expression on the right can be rewritten as a) x == 0 y <= 0 b) x == 0 && y <= 0 c) x == 0 y < 0 d) x == 0 && y < 0 e) x!= 0 && y > The expression on the right can be rewritten as a) true (because this is always true) b) false (because this is always false) c) n > 50 n <= 60 d) n >= 50 && n < 60 e) n > 50 && n <= 60!( x!= 0 y > 0 )!( n <= 50 n > 60 )

18 D 77. m1 and m2 must each return a boolean. True False 78. If m1 returns true, then method m2 will not be called. True False 79. If m1 returns false, then method m2 will not be called. True False 80. Select the TRUE statement(s). a) If the user enters YES, then A is displayed. b) If the user enters yes, then A is displayed. c) This code will not compile because you cannot use == with two objects. d) This code compiles but will always display, no matter what the user enters. if ( m1() && m2() ) // code A else // code String s1 = "yes"; String s2; /* Code that asks the user to enter a word and assigns it to s2. */ if ( s1 == s2 ) System.out.println( "A" ); else System.out.println( "" ); D 81. Select the TRUE statement a) All three expressions may sometimes throw a run-time exception. b) All three expressions always throw a runtime exception. c) Only expression (A) sometimes throw a runtime exception. Expressions () and (C) never throw a run-time exception. d) Expressions (A) and () sometimes throw run-time exceptions. Expression (C) never throws a run-time exception. e) None of the three expressions ever throw a run-time exception. Assume that all variables have been declared and initialized. n may or may not be a valid index for the array. (A) a[n] > 0 && n < a.length && n >= 0 () n < a.length && a[n] > 0 && n >= 0 (C) n < a.length && n >= 0 && a[n] > 0 Hint. This question is about short-circuit evaluation. 82. What is displayed? public static void main(string[] args) { int [] a = { 1, 2, 3 ; m1( a ); for ( int num : a ) System.out.print( num + " " ); public static void m1( int [] a ){ int [] b = new int[ a.length ]; for ( int k = 0; k < b.length; k++ ) b[k] = 10*a[k]; a = b;

19 83. What does this code print? for ( int k = 1; k < 5; k++ ){ for ( int i = 1; i < k; i++ ){ System.out.print( k + " " ); System.out.println(); C C C Assume the code to the right compiles and runs. 84. Select the True statement. a) a must be an instance variable. b) a must be a class variable. c) a may be an instance variable or a class variable d) none of the above 85. Select the True statement. a) b must be an instance variable. b) b must be a class variable. c) b may be an instance variable or a class variable d) none of the above 86. When this is run, the first two strings to be printed are: java.lang.object@168ca82 java.lang.object@8bf035 The next two strings are: a) something that looks like the first two strings b) hey woof 87. This code demonstrates the concept of: a) overloading / compile time polymorphism b) overriding / runtime polymorphism c) neither of the above 88. Select the TRUE statement. a) x must be an instance variable b) x must be a class variable c) x may be an instance or class variable. 89. Select the TRUE statement. a) y must be an instance variable b) y must be a class variable c) y may be an instance or class variable. 90. Select the TRUE statement. a) methodz must be an instance method b) methodz must be a class method c) methodz may be an instance or class method. 91. Select the TRUE statement. a) methodzzzz must be an instance method b) methodzzzz must be a class method c) methodzzzz may be an instance or class method. public class Dog { // instance variables // constructors and methods public static int method1(){ return a; public int method2() return b; Object [] a = new Object[4]; a[0] = new Object(); a[1] = new Object(); a[2] = "hey"; a[3] = new Dog( 5 ); for ( Object x : a ) System.out.println( x ); public void methoda() { System.out.println( x ); public static void method() { System.out.println( y ); public void methodc() { methodz(); public static void methodd() { methodzzzz();

20 92. What is displayed? public static void main( String [] args ) { Dog a = new Dog( 5 ); dohtem( a ); System.out.println( a.get() ); 11 public static void dohtem( Dog e ){ Dog y = e; y.set( 11 ); 93. What is displayed? public static void main( String [] args ) { Dog a = new Dog( 5 ); dohtem( a ); System.out.println( a.get() ); 5 A A A 94. This method returns a) 3 b) 3.0 c) This displays a) 9H b) 45H 96. This displays a) T9 b) T c has a value of a) 4.0 b) c has a value of a) 4.0 b) c has a value of a) 4.0 b) 4.9 public static void dohtem( Dog e ){ e = new Dog( 14 ); public double mm(){ return 38 / 10; int a = 4; int b = 5; System.out.println( a + b + "H" ); int a = 4; int b = 5; System.out.println( "T" + a + b ); int a = 49; int b = 10; double c = a/b; int a = 49; int b = 10; double c = 1.0*a/b; int a = 49; int b = 10; double c = a/b*1.0;

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal APCS A Midterm Review You will have a copy of the one page Java Quick Reference sheet. This is the same reference that will be available to you when you take the AP Computer Science exam. 1. n bits can

More information

Unit 5: More on Classes/Objects Notes

Unit 5: More on Classes/Objects Notes Unit 5: More on Classes/Objects Notes AP CS A The Difference between Primitive and Object/Reference Data Types First, remember the definition of a variable. A variable is a. So, an obvious question is:

More information

AP CS Unit 6: Inheritance Notes

AP CS Unit 6: Inheritance Notes AP CS Unit 6: Inheritance Notes Inheritance is an important feature of object-oriented languages. It allows the designer to create a new class based on another class. The new class inherits everything

More information

TeenCoder : Java Programming (ISBN )

TeenCoder : Java Programming (ISBN ) TeenCoder : Java Programming (ISBN 978-0-9887070-2-3) and the AP * Computer Science A Exam Requirements (Alignment to Tennessee AP CS A course code 3635) Updated March, 2015 Contains the new 2014-2015+

More information

AP CS Unit 8: Inheritance Exercises

AP 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 information

AP CS Unit 6: Inheritance Exercises

AP 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 information

CompuScholar, Inc. 9th - 12th grades

CompuScholar, Inc. 9th - 12th grades CompuScholar, Inc. Alignment to the College Board AP Computer Science A Standards 9th - 12th grades AP Course Details: Course Title: Grade Level: Standards Link: AP Computer Science A 9th - 12th grades

More information

AP CS Unit 7: Arrays Exercises

AP CS Unit 7: Arrays Exercises AP CS Unit 7: Arrays Exercises 1. What is displayed? int [] a = new int[ 3 ]; System.out.println(a.length ); 2. What is displayed? int [] sting = { 34, 23, 67, 89, 12 ; System.out.println( sting[ 1 ] );

More information

AP Computer Science A Unit 7. Notes on Arrays

AP Computer Science A Unit 7. Notes on Arrays AP Computer Science A Unit 7. Notes on Arrays Arrays. An array is an object that consists of an of similar items. An array has a single name and the items in an array are referred to in terms of their

More information

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this

More information

CS-202 Introduction to Object Oriented Programming

CS-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 information

IMACS: AP Computer Science A

IMACS: AP Computer Science A IMACS: AP Computer Science A OVERVIEW This course is a 34-week, 4 classroom hours per week course for students taking the College Board s Advanced Placement Computer Science A exam. It is an online course

More information

Language Features. 1. The primitive types int, double, and boolean are part of the AP

Language Features. 1. The primitive types int, double, and boolean are part of the AP Language Features 1. The primitive types int, double, and boolean are part of the AP short, long, byte, char, and float are not in the subset. In particular, students need not be aware that strings are

More information

AP 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. 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 information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

APCS Semester #1 Final Exam Practice Problems

APCS Semester #1 Final Exam Practice Problems Name: Date: Per: AP Computer Science, Mr. Ferraro APCS Semester #1 Final Exam Practice Problems The problems here are to get you thinking about topics we ve visited thus far in preparation for the semester

More information

Rules and syntax for inheritance. The boring stuff

Rules and syntax for inheritance. The boring stuff Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for

More information

Practice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course

Practice 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 information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II

Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Ad hoc-polymorphism Outline Method overloading Sub-type Polymorphism Method overriding Dynamic

More information

ITI Introduction to Computing II

ITI 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 information

Array. Prepared By - Rifat Shahriyar

Array. Prepared By - Rifat Shahriyar Java More Details Array 2 Arrays A group of variables containing values that all have the same type Arrays are fixed length entities In Java, arrays are objects, so they are considered reference types

More information

AP COMPUTER SCIENCE A DIAGNOSTIC EXAM. Multiple Choice Section Time - 1 hour and 15 minutes Number of questions - 40 Percent of total grade - 50

AP COMPUTER SCIENCE A DIAGNOSTIC EXAM. Multiple Choice Section Time - 1 hour and 15 minutes Number of questions - 40 Percent of total grade - 50 AP COMPUTER SCIENCE A DIAGNOSTIC EXAM Multiple Choice Section Time - 1 hour and 15 minutes Number of questions - 40 Percent of total grade - 50 Directions: Determine the answer to each of the following

More information

Computer Science 1 Ah

Computer Science 1 Ah UNIVERSITY OF EDINBURGH course CS0077 COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS Computer Science 1 Ah Resit Examination Specimen Solutions Date: Monday 1st September 2003 Time: 09:30 11:00

More information

Chief Reader Report on Student Responses:

Chief Reader Report on Student Responses: Chief Reader Report on Student Responses: 2017 AP Computer Science A Free-Response Questions Number of Students Scored 60,519 Number of Readers 308 Score Distribution Exam Score N %At Global Mean 3.15

More information

COP 3330 Final Exam Review

COP 3330 Final Exam Review COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time

More information

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University Day 4 COMP1006/1406 Summer 2016 M. Jason Hinek Carleton University today s agenda assignments questions about assignment 2 a quick look back constructors signatures and overloading encapsulation / information

More information

Solution to Test of Computer Science 203x Level Score: / 100 Time: 100 Minutes

Solution to Test of Computer Science 203x Level Score: / 100 Time: 100 Minutes Solution to Test of Computer Science 203x Level Score: / 100 Time: 100 Minutes PART I: Multiple Choice (3 points each) Note: The correct answer can be any combination of A, B, C, D. Example, Sample Question:

More information

ITI Introduction to Computing II

ITI 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 information

https://asd-pa.perfplusk12.com/admin/admin_curric_maps_display.asp...

https://asd-pa.perfplusk12.com/admin/admin_curric_maps_display.asp... 1 of 8 8/27/2014 2:15 PM Units: Teacher: ProgIIIAPCompSci, CORE Course: ProgIIIAPCompSci Year: 2012-13 Computer Systems This unit provides an introduction to the field of computer science, and covers the

More information

Selected Questions from by Nageshwara Rao

Selected Questions from  by Nageshwara Rao Selected Questions from http://way2java.com by Nageshwara Rao Swaminathan J Amrita University swaminathanj@am.amrita.edu November 24, 2016 Swaminathan J (Amrita University) way2java.com (Nageshwara Rao)

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Inheritance and Polymorphism Dr. M. G. Abbas Malik Assistant Professor Faculty of Computing and IT (North Jeddah Branch) King Abdulaziz University, Jeddah, KSA mgmalik@kau.edu.sa www.sanlp.org/malik/cpit305/ap.html

More information

CS1150 Principles of Computer Science Objects and Classes

CS1150 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 information

Declarations and Access Control SCJP tips

Declarations and Access Control  SCJP tips Declarations and Access Control www.techfaq360.com SCJP tips Write code that declares, constructs, and initializes arrays of any base type using any of the permitted forms both for declaration and for

More information

CMSC132 Summer 2018 Midterm 1

CMSC132 Summer 2018 Midterm 1 CMSC132 Summer 2018 Midterm 1 First Name (PRINT): Last Name (PRINT): Instructions This exam is a closed-book and closed-notes exam. Total point value is 100 points. The exam is a 80 minutes exam. Please

More information

COMP 250 Fall inheritance Nov. 17, 2017

COMP 250 Fall inheritance Nov. 17, 2017 Inheritance In our daily lives, we classify the many things around us. The world has objects like dogs and cars and food and we are familiar with talking about these objects as classes Dogs are animals

More information

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java

More information

C a; C b; C e; int c;

C a; C b; C e; int c; CS1130 section 3, Spring 2012: About the Test 1 Purpose of test The purpose of this test is to check your knowledge of OO as implemented in Java. There is nothing innovative, no deep problem solving, no

More information

Chapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles,

Chapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles, Chapter 11 Inheritance and Polymorphism 1 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the best way to design

More information

Subclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented

Subclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented Table of Contents L01 - Introduction L02 - Strings Some Examples Reserved Characters Operations Immutability Equality Wrappers and Primitives Boxing/Unboxing Boxing Unboxing Formatting L03 - Input and

More information

CISC-124. Passing Parameters. A Java method cannot change the value of any of the arguments passed to its parameters.

CISC-124. Passing Parameters. A Java method cannot change the value of any of the arguments passed to its parameters. CISC-124 20180215 These notes are intended to summarize and clarify some of the topics that have been covered recently in class. The posted code samples also have extensive explanations of the material.

More information

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018 Birkbeck (University of London) Software and Programming 1 In-class Test 2.1 22 Mar 2018 Student Name Student Number Answer ALL Questions 1. What output is produced when the following Java program fragment

More information

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8 Epic Test Review 1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4 Write a line of code that outputs the phase Hello World to the console without creating a new line character. System.out.print(

More information

CMSC132 Summer 2018 Midterm 1. Solution

CMSC132 Summer 2018 Midterm 1. Solution CMSC132 Summer 2018 Midterm 1 Solution First Name (PRINT): Last Name (PRINT): Instructions This exam is a closed-book and closed-notes exam. Total point value is 100 points. The exam is a 80 minutes exam.

More information

CS 314 Midterm 1 Spring 2014

CS 314 Midterm 1 Spring 2014 Points off 1 2 3A 3B 4 Total off Net Score CS 314 Midterm 1 Spring 2014 Your Name Your UTEID Instructions: 1. There are 4 questions on this test. 82 points available. Scores will be scaled to 200 points.

More information

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. CMSC 131: Chapter 28 Final Review: What you learned this semester The Big Picture Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. Java

More information

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each Your Name: Your Pitt (mail NOT peoplesoft) ID: Part Question/s Points available Rubric Your Score A 1-6 6 1 pt each B 7-12 6 1 pt each C 13-16 4 1 pt each D 17-19 5 1 or 2 pts each E 20-23 5 1 or 2 pts

More information

Computer Science II (20073) Week 1: Review and Inheritance

Computer Science II (20073) Week 1: Review and Inheritance Computer Science II 4003-232-01 (20073) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Hardware and Software Hardware Physical devices in a computer system

More information

Operators and Expressions

Operators and Expressions Operators and Expressions Conversions. Widening and Narrowing Primitive Conversions Widening and Narrowing Reference Conversions Conversions up the type hierarchy are called widening reference conversions

More information

1 Shyam sir JAVA Notes

1 Shyam sir JAVA Notes 1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write

More information

AP CS Unit 6: Inheritance Programs

AP CS Unit 6: Inheritance Programs AP CS Unit 6: Inheritance Programs Program 1. Complete the Rectangle class. The Rectangle public class Rectangle{ class represents private int x1, y1, x2, y2; a rectangle in a standard coordinate plane

More information

AP CS Unit 7: Interfaces Exercises 1. Select the TRUE statement(s).

AP CS Unit 7: Interfaces Exercises 1. Select the TRUE statement(s). AP CS Unit 7: Interfaces Exercises 1. Select the TRUE statement(s). a) This code will not compile because a method cannot specify an interface as a parameter. public class Testing { public static void

More information

Term 1 Unit 1 Week 1 Worksheet: Output Solution

Term 1 Unit 1 Week 1 Worksheet: Output Solution 4 Term 1 Unit 1 Week 1 Worksheet: Output Solution Consider the following what is output? 1. System.out.println("hot"); System.out.println("dog"); Output hot dog 2. System.out.print("hot\n\t\t"); System.out.println("dog");

More information

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution Ch 5 Arrays Multiple Choice Test 01. An array is a ** (A) data structure with one, or more, elements of the same type. (B) data structure with LIFO access. (C) data structure, which allows transfer between

More information

CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name:

CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name: CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, 2017 Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : If a child overrides

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

Objective Questions. BCA Part III Paper XIX (Java Programming) page 1 of 5

Objective Questions. BCA Part III Paper XIX (Java Programming) page 1 of 5 Objective Questions BCA Part III page 1 of 5 1. Java is purely object oriented and provides - a. Abstraction, inheritance b. Encapsulation, polymorphism c. Abstraction, polymorphism d. All of the above

More information

Inheritance (continued) Inheritance

Inheritance (continued) Inheritance Objectives Chapter 11 Inheritance and Polymorphism Learn about inheritance Learn about subclasses and superclasses Explore how to override the methods of a superclass Examine how constructors of superclasses

More information

Prelim 1. Solution. CS 2110, 14 March 2017, 7:30 PM Total Question Name Short answer

Prelim 1. Solution. CS 2110, 14 March 2017, 7:30 PM Total Question Name Short answer Prelim 1. Solution CS 2110, 14 March 2017, 7:30 PM 1 2 3 4 5 Total Question Name Short answer OO Recursion Loop invariants Max 1 36 33 15 15 100 Score Grader 1. Name (1 point) Write your name and NetID

More information

Java Magistère BFA

Java Magistère BFA Java 101 - Magistère BFA Lesson 3: Object Oriented Programming in Java Stéphane Airiau Université Paris-Dauphine Lesson 3: Object Oriented Programming in Java (Stéphane Airiau) Java 1 Goal : Thou Shalt

More information

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17 List of Programs xxv List of Figures xxix List of Tables xxxiii Preface to second version xxxv PART 1 Structured Programming 1 1 Getting started 3 1.1 Programming 3 1.2 Editing source code 5 Source code

More information

Building Java Programs

Building Java Programs Building Java Programs A Back to Basics Approach Stuart Reges I Marty Stepp University ofwashington Preface 3 Chapter 1 Introduction to Java Programming 25 1.1 Basic Computing Concepts 26 Why Programming?

More information

CS 251 Intermediate Programming Inheritance

CS 251 Intermediate Programming Inheritance CS 251 Intermediate Programming Inheritance Brooke Chenoweth University of New Mexico Spring 2018 Inheritance We don t inherit the earth from our parents, We only borrow it from our children. What is inheritance?

More information

Advanced Placement Computer Science. Inheritance and Polymorphism

Advanced Placement Computer Science. Inheritance and Polymorphism Advanced Placement Computer Science Inheritance and Polymorphism What s past is prologue. Don t write it twice write it once and reuse it. Mike Scott The University of Texas at Austin Inheritance, Polymorphism,

More information

CS 307 Midterm 2 Spring 2011

CS 307 Midterm 2 Spring 2011 Points off 1 2 3 4 5 Total off Net Score Exam Number: CS 307 Midterm 2 Spring 2011 Name UTEID login name TA's Name: Dan Muhibur Oliver (Circle One) Instructions: 1. Please turn off your cell phones and

More information

INHERITANCE. Spring 2019

INHERITANCE. Spring 2019 INHERITANCE Spring 2019 INHERITANCE BASICS Inheritance is a technique that allows one class to be derived from another A derived class inherits all of the data and methods from the original class Suppose

More information

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2014

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2014 CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2014 Name: This exam consists of 5 problems on the following 6 pages. You may use your double- sided hand- written 8 ½ x 11 note sheet

More information

COE 212 Engineering Programming. Welcome to the Final Exam Tuesday December 15, 2015

COE 212 Engineering Programming. Welcome to the Final Exam Tuesday December 15, 2015 1 COE 212 Engineering Programming Welcome to the Final Exam Tuesday December 15, 2015 Instructors: Dr. Salim Haddad Dr. Bachir Habib Dr. Joe Tekli Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1.

More information

Object Oriented Programming. Java-Lecture 11 Polymorphism

Object Oriented Programming. Java-Lecture 11 Polymorphism Object Oriented Programming Java-Lecture 11 Polymorphism Abstract Classes and Methods There will be a situation where you want to develop a design of a class which is common to many classes. Abstract class

More information

Exam Duration: 2hrs and 30min Software Design

Exam Duration: 2hrs and 30min Software Design Exam Duration: 2hrs and 30min. 433-254 Software Design Section A Multiple Choice (This sample paper has less questions than the exam paper The exam paper will have 25 Multiple Choice questions.) 1. Which

More information

Use the scantron sheet to enter the answer to questions (pages 1-6)

Use 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 information

Inheritance. Notes Chapter 6 and AJ Chapters 7 and 8

Inheritance. Notes Chapter 6 and AJ Chapters 7 and 8 Inheritance Notes Chapter 6 and AJ Chapters 7 and 8 1 Inheritance you know a lot about an object by knowing its class for example what is a Komondor? http://en.wikipedia.org/wiki/file:komondor_delvin.jpg

More information

Introduction to Computer Science Unit 2. Exercises

Introduction to Computer Science Unit 2. Exercises Introduction to Computer Science Unit 2. Exercises Note: Curly brackets { are optional if there is only one statement associated with the if (or ) statement. 1. If the user enters 82, what is 2. If the

More information

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community CSCI-12 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community http://csc.cs.rit.edu 1. Provide a detailed explanation of what the following code does: 1 public boolean checkstring

More information

Java Fundamentals (II)

Java Fundamentals (II) Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Java Fundamentals (II) Marco Piccioni static imports Introduced in 5.0 Imported static members of a class

More information

Constructor. Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

Constructor. 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 information

CMSC 341. Nilanjan Banerjee

CMSC 341. Nilanjan Banerjee CMSC 341 Nilanjan Banerjee http://www.csee.umbc.edu/~nilanb/teaching/341/ Announcements Just when you thought Shawn was going to teach this course! On a serious note: register on Piazza I like my classes

More information

Instructions. This exam has 7 questions, worth 10 points each. You have 50 minutes.

Instructions. This exam has 7 questions, worth 10 points each. You have 50 minutes. COS 126 Written Exam 1 Spring 18 Instructions. This exam has 7 questions, worth 10 points each. You have 50 minutes. Resources. You may reference your optional one-sided 8.5-by-11 handwritten "cheat sheet"

More information

Topic 5 Polymorphism. " Inheritance is new code that reuses old code. Polymorphism is old code that reuses new code.

Topic 5 Polymorphism.  Inheritance is new code that reuses old code. Polymorphism is old code that reuses new code. Topic 5 Polymorphism " Inheritance is new code that reuses old code. Polymorphism is old code that reuses new code. 1 Polymorphism Another feature of OOP literally having many forms object variables in

More information

Practice for Chapter 11

Practice 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 information

L o o p s. for(initializing expression; control expression; step expression) { one or more statements }

L o o p s. for(initializing expression; control expression; step expression) { one or more statements } L o o p s Objective #1: Explain the importance of loops in programs. In order to write a non trivial computer program, you almost always need to use one or more loops. Loops allow your program to repeat

More information

CS 1302 Chapter 9 (Review) Object & Classes

CS 1302 Chapter 9 (Review) Object & Classes CS 1302 Chapter 9 (Review) Object & Classes Reference Sections 9.2-9.5, 9.7-9.14 9.2 Defining Classes for Objects 1. A class is a blueprint (or template) for creating objects. A class defines the state

More information

Class, Variable, Constructor, Object, Method Questions

Class, Variable, Constructor, Object, Method Questions Class, Variable, Constructor, Object, Method Questions http://www.wideskills.com/java-interview-questions/java-classes-andobjects-interview-questions https://www.careerride.com/java-objects-classes-methods.aspx

More information

CH. 2 OBJECT-ORIENTED PROGRAMMING

CH. 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 information

Agenda. Objects and classes Encapsulation and information hiding Documentation Packages

Agenda. 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 information

Lecture 5: Methods CS2301

Lecture 5: Methods CS2301 Lecture 5: Methods NADA ALZAHRANI CS2301 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. 2 Solution public static int sum(int i1, int i2) { int

More information

Informatik II (D-ITET) Tutorial 6

Informatik II (D-ITET) Tutorial 6 Informatik II (D-ITET) Tutorial 6 TA: Marian George, E-mail: marian.george@inf.ethz.ch Distributed Systems Group, ETH Zürich Exercise Sheet 5: Solutions and Remarks Variables & Methods beginwithlowercase,

More information

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014 Lesson 10A OOP Fundamentals By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Definition Pointers vs containers Object vs primitives Constructors Methods Object class

More information

Chapter 10 Inheritance and Polymorphism. Dr. Hikmat Jaber

Chapter 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 information

APCS Assessment Sheet Consider the following program segment int count = 1;

APCS Assessment Sheet Consider the following program segment int count = 1; APCS Assessment Sheet 1 1. Consider the following program segment int count = 1; for(int p = 0; p < 5; p++) if(p % 2 = = 0) count++; else count += 2; System.out.println(count); What value is displayed?

More information

Lecture Notes Chapter #9_b Inheritance & Polymorphism

Lecture Notes Chapter #9_b Inheritance & Polymorphism Lecture Notes Chapter #9_b Inheritance & Polymorphism Inheritance results from deriving new classes from existing classes Root Class all java classes are derived from the java.lang.object class GeometricObject1

More information

Prelim 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 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 information

Object Oriented Programming and Design in Java. Session 10 Instructor: Bert Huang

Object Oriented Programming and Design in Java. Session 10 Instructor: Bert Huang Object Oriented Programming and Design in Java Session 10 Instructor: Bert Huang Announcements Homework 2 due Mar. 3rd, 11 AM two days Midterm review Monday, Mar. 8th Midterm exam Wednesday, Mar. 10th

More information

CSE 142 Su 04 Computer Programming 1 - Java. Objects

CSE 142 Su 04 Computer Programming 1 - Java. Objects Objects Objects have state and behavior. State is maintained in instance variables which live as long as the object does. Behavior is implemented in methods, which can be called by other objects to request

More information

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003 1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 7, 2003 Name: Email Address: TA: Section: You have 90 minutes to complete this exam. For coding questions, you do not need to

More information

QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 27 th March

QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 27 th March QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 27 th March 2006 11.05-12.35 Please fill in your Examination Number here: Student Number here: MODEL ANSWERS All

More information

Inheritance (Part 2) Notes Chapter 6

Inheritance (Part 2) Notes Chapter 6 Inheritance (Part 2) Notes Chapter 6 1 Object Dog extends Object Dog PureBreed extends Dog PureBreed Mix BloodHound Komondor... Komondor extends PureBreed 2 Implementing Inheritance suppose you want to

More information

AP CS Unit 7: Interfaces. Programs

AP CS Unit 7: Interfaces. Programs AP CS Unit 7: Interfaces. Programs You cannot use the less than () operators with objects; it won t compile because it doesn t always make sense to say that one object is less than

More information

Lecture 13: Two- Dimensional Arrays

Lecture 13: Two- Dimensional Arrays Lecture 13: Two- Dimensional Arrays Building Java Programs: A Back to Basics Approach by Stuart Reges and Marty Stepp Copyright (c) Pearson 2013. All rights reserved. Nested Loops Nested loops nested loop:

More information

Computer Science E-119 Fall Problem Set 1. Due before lecture on Wednesday, September 26

Computer Science E-119 Fall Problem Set 1. Due before lecture on Wednesday, September 26 Due before lecture on Wednesday, September 26 Getting Started Before starting this assignment, make sure that you have completed Problem Set 0, which can be found on the assignments page of the course

More information