Instruction to students:

Similar documents
Questions Answer Key Questions Answer Key Questions Answer Key

Questions Answer Key Questions Answer Key Questions Answer Key

Chapter 8 Objects and Classes Dr. Essam Halim Date: Page 1

Practice for Chapter 11

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

CIS 265/506 Exam1 Spring 2012 Prof. V. Matos Exam Last Name First Name:

CS 113 MIDTERM EXAM 2 SPRING 2013

Questions Answer Key Questions Answer Key Questions Answer Key

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

Full download all chapters instantly please go to Solutions Manual, Test Bank site: testbanklive.com

Date: Dr. Essam Halim

Full file at Chapter 2 - Inheritance and Exception Handling

Practice Questions for Chapter 9

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Midterm Exam CS 251, Intermediate Programming March 6, 2015

Final Examination Semester 2 / Year 2010

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

CIS265 - Spring Exam 2 First Name Last Name CSU#

Final Examination Semester 2 / Year 2012

public class Test { static int age; public static void main (String args []) { age = age + 1; System.out.println("The age is " + age); }

Prelim 1 Solutions. CS 2110, March 10, 2015, 5:30 PM Total Question True False. Loop Invariants Max Score Grader

Chapter 6 Introduction to Defining Classes

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

Final Examination Semester 2 / Year 2011

Come & Join Us at VUSTUDENTS.net

Java for Non Majors. Final Study Guide. April 26, You will have an opportunity to earn 20 extra credit points.

B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA

Programming II (CS300)

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

CMSC 331 Second Midterm Exam

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

Declarations and Access Control SCJP tips

Selected Java Topics

Full file at

Midterm assessment - MAKEUP Fall 2010

UNIVERSITI SAINS MALAYSIA. CIT502 Object-Oriented Programming and Software Engineering

Casting -Allows a narrowing assignment by asking the Java compiler to "trust us"

COMP1008 Exceptions. Runtime Error

Chapter 1: Introduction to Computers, Programs, and Java

VALLIAMMAI ENGINEERING COLLEGE

Fundamentals of Object Oriented Programming

CSC Java Programming, Fall Java Data Types and Control Constructs

Programming II (CS300)

Table of Contents. Chapter 1 Getting Started with Java SE 7 1. Chapter 2 Exploring Class Members in Java 15. iii. Introduction of Java SE 7...

B2.52-R3: INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING THROUGH JAVA

Midterm Exam CS 251, Intermediate Programming March 12, 2014

DHANALAKSHMI SRINIVASAN COLLEGE OF ENGINEERING AND TECHNOLOGY ACADEMIC YEAR (ODD SEM)

WOSO Source Code (Java)

Compaq Interview Questions And Answers

Class, Variable, Constructor, Object, Method Questions

1 Shyam sir JAVA Notes

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC

CLASS DESIGN. Objectives MODULE 4

CS 113 PRACTICE FINAL

COP 3330 Final Exam Review

Selected Questions from by Nageshwara Rao

Prelim 1. CS 2110, 13 March 2018, 5:30 PM Total Question Name Short answer

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

15CS45 : OBJECT ORIENTED CONCEPTS

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

Java Inheritance. Written by John Bell for CS 342, Spring Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources.

CS 11 java track: lecture 3

UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

SELF-STUDY. Glossary

Object Oriented Programming with Java. Unit-1

Introduction to Programming Using Java (98-388)

CS 180 Final Exam Review 12/(11, 12)/08

APCS Unit 5 Exam. Assuming all four classes have a default constructor, which of the following statements would result in an error from the compiler?

CS/B.TECH/CSE(OLD)/SEM-6/CS-605/2012 OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

S.E. Sem. III [CMPN] Object Oriented Programming Methodology

CS 209 Programming in Java #10 Exception Handling

Prelim 1. CS 2110, 13 March 2018, 7:30 PM Total Question Name Short answer

Lecture 28. Exceptions and Inner Classes. Goals. We are going to talk in more detail about two advanced Java features:

More About Objects. Zheng-Liang Lu Java Programming 255 / 282

Inheritance. Chapter 7. Chapter 7 1

Full file at

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

More on Objects in JAVA TM

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

POLYTECHNIC OF NAMIBIA SCHOOL OF COMPUTING AND INFORMATICS DEPARTMENT OF COMPUTER SCIENCE

Prelim 1 SOLUTION. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants. Recursion OO Short answer

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed

Chapter 14. Exception Handling and Event Handling

CS-202 Introduction to Object Oriented Programming

Computer Programming, I. Laboratory Manual. Final Exam Solution

COMP 202. More on OO. CONTENTS: static revisited this reference class dependencies method parameters variable scope method overloading

Object-Oriented Concepts

CS1150 Principles of Computer Science Objects and Classes

Java Object Oriented Design. CSC207 Fall 2014

Arrays Classes & Methods, Inheritance

Final Exam CS 251, Intermediate Programming December 13, 2017

Java for Non Majors Spring 2018

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.

Exception-Handling Overview

Chapter 5 Object-Oriented Programming

Inheritance. One class inherits from another if it describes a specialized subset of objects Terminology:

Transcription:

Benha University 2 nd Term (2012) Final Exam Class: 2 nd Year Students Subject: Object Oriented Programming Faculty of Computers & Informatics Date: 20/5/2012 Time: 3 hours Examiner: Dr. Essam Halim Instruction to students: 1. Language allowed to answer is the English language. 2. You should attempt 40 out of the 50 MCQ questions in Section I. 3. You should attempt all of Section II (Section II comprises questions 2, 3, and 4). 4. The exam paper is 14 pages long, and is in 2 sections. 5. The approximate allocation of marks is shown in brackets by the questions. 6. Section I contains multiple choice questions. Answer for the multiple choice questions should be written in the next table move it to the answer sheet. Section I : Key answer for the multiple choice questions Questions 1 2 3 4 5 6 7 8 9 10 Questions 11 12 13 14 15 16 17 18 19 20 Questions 21 22 23 24 25 26 27 28 29 30 Questions 31 32 33 34 35 36 37 38 39 40 Questions 41 42 43 44 45 46 47 48 49 50 Page 1 of 15

Answer the following questions: Section I [Total 60] Q(1): Multiple choice questions Answer only 40 of the following 50 multiple choice questions, by selecting the correct answer in each. Place the answer on the special MCQ form. Each question [1.5 Mark] 1 If a number is too large to be stored in a variable of the float type, it. A. causes overflow B. causes underflow C. causes no error D. cannot happen in Java 2 What is i printed in the following code? int j = 0; int i = j++ + j * 5; System.out.println("What is i? " + i); A. 0 B. 1 C. 5 D. 6 3 Analyze the following code. import javax.swing.*; public class ShowErrors { int i; int j; String s = JOptionPane.showInputDialog(null, "Enter an integer", "Input", JOptionPane.QUESTION_MESSAGE); j = Integer.parseInt(s); i = (i + 4); A. The program cannot compile because j is not initialized. B. The program cannot compile because i does not have an initial value when it is used in i = i + 4; C. The program compiles but has a runtime error because i does not have an initial value when it is used in i = i + 4; D. The program compiles and runs fine. Page 2 of 15

4 Suppose x=10 and y=10 what is x after evaluating the expression (y >= 10) (x-- > 10). A. 9 B. 10 C. 11 5 What is y after the following statement is executed? x = 0; y = (x > 0)? 10 : -10; A. -10 B. 0 C. 10 D. 20 E. Illegal expression 6 How many times will the following code print "Welcome to Java"? int count = 0; do { System.out.println("Welcome to Java"); count++; while (count < 10); A. 8 B. 9 C. 10 D. 11 E. 0 7 Is the following loop correct? for (; ; ); A. Yes B. No 8 How many times is the println statement executed? for (int i = 0; i < 10; i++) for (int j = 0; j < i; j++) System.out.println(i * j) A. 100 B. 20 C. 10 D. 45 Page 3 of 15

9 What is sum after the following loop terminates? int sum = 0; int item = 0; do { item++; sum += item; if (sum >= 4) continue; while (item < 5); A. 15 B. 16 C. 17 D. 18 10 Will the following program terminate? int balance = 10; while (true) { if (balance < 9) continue; balance = balance - 9; A. Yes B. No 11 The signature of a method consists of. A. method name B. method name and parameter list C. return type, method name, and parameter list D. parameter list 12 Given the following method static void nprint(string message, int n) { while (n > 0) { System.out.print(message); n--; What is the printout of the call nprint('a', 4)? A. aaaaa B. aaaa C. aaa D. invalid call Page 4 of 15

13 The client can use a method without knowing how it is implemented. The details of the implementation are encapsulated in the method and hidden from the client who invokes the method. This is known as. A. information hiding B. encapsulation C. method hiding D. simplifying method 14 is to implement one method in the structure chart at a time from the top to the bottom. A. Bottom-up approach B. Top-down approach C. Bottom-up and top-down approach D. Stepwise refinement 15 Which of the following statements is valid? A. int i = new int(30); B. double d[] = new double[30]; C. int[] i = {3, 4, 3, 2; D. char[] c = new char(); E. char[] c = new char[4]{'a', 'b', 'c', 'd'; 16 Analyze the following code: final int[] x = {1, 2, 3, 4; int[] y = x; x = new int[2]; for (int i = 0; i < y.length; i++) System.out.print(y[i] + " "); A. The program displays 1 2 3 4 B. The program displays 0 0 C. The program has a compile error on the statement x = new int[2], because x is final and cannot be changed. D. The elements in the array x cannot be changed, because x is final. 17 When you return an array from a method, the method returns. A. a copy of the array B. a copy of the first element C. the reference of the array D. the length of the array Page 5 of 15

18 Which of the following declarations are correct? A. public static void print(string strings, double numbers) B. public static void print(double numbers, String name) C. public static double print(double d1, double d2) D. public static void print(double numbers) E. public static void print(int n, double numbers) 19 What is the printout of the following program? int[][] values = {{3, 4, 5, 1, {33, 6, 1, 2; for (int row = 0; row < values.length; row++) { System.out.print(m(values[row]) + " "); public static int m(int[] list) { int v = list[0]; for (int i = 1; i < list.length; i++) if (v < list[i]) v = list[i]; return v; A. 3 33 B. 1 1 C. 5 6 D. 5 33 E. 33 5 20 Which of the following statements are true? A. Multiple constructors can be defined in a class. B. Constructors do not have a return type, not even void. C. Constructors must have the same name as the class itself. D. Constructors are invoked using the new operator when an object is created. 21 Variables that are shared by every instances of a class are. A. public variables B. private variables C. instance variables D. class variables Page 6 of 15

22 You should add the static keyword in the place of? in Line in the following code: 1 2 private int age; 3 4 public? int square(int n) { 5 return n * n; 6 7 8 public? int getage() { 9 10 A. in line 4 B. in line 8 C. in both line 4 and line 8 D. none 23 Analyze the following code. int n = 2; xmethod(n); System.out.println("n is " + n); void xmethod(int n) { n++; A. The code has a compile error because xmethod does not return a value. B. The code has a compile error because xmethod is not declared static. C. The code prints n is 1. D. The code prints n is 2. E. The code prints n is 3. 24 Analyze the following code: private int t; int x; System.out.println(t); A. The variable t is not initialized and therefore causes errors. B. The variable t is private and therefore cannot be accessed in the main method. C. t is non-static and it cannot be referenced in a static context in the main method. D. The variable x is not initialized and therefore causes errors. E. The program compiles and runs fine. Page 7 of 15

25 What is the output of the following program? import java.util.date; Date date = new Date(1234567); m1(date); System.out.print(date.getTime() + " "); m2(date); System.out.println(date.getTime()); public static void m1(date date) { date = new Date(7654321); public static void m2(date date) { date.settime(7654321); A. 1234567 1234567 B. 1234567 7654321 C. 7654321 1234567 D. 7654321 7654321 26 What is the output of the following code? String s1 = "Welcome to Java!"; String s2 = "Welcome to Java!"; if (s1 == s2) System.out.println("s1 and s2 reference to the same String object"); else System.out.println("s1 and s2 reference to different String objects"); A. s1 and s2 reference to the same String object B. s1 and s2 reference to different String objects 27 What is the output of running class C? class A { public A() { System.out.println( "The default constructor of A is invoked"); class B extends A { public B() { System.out.println( "The default constructor of B is invoked"); public class C { B b = new B(); Page 8 of 15

A. Nothing displayed B. "The default constructor of B is invoked" C. "The default constructor of A is invoked""the default constructor of B is invoked" D. "The default constructor of B is invoked""the default constructor of A is invoked" E. "The default constructor of A is invoked" 28 Which of the statements regarding the super keyword is incorrect? A. You can use super to invoke a super class constructor. B. You can use super to invoke a super class method. C. You can use super.super.p to invoke a method in superclass's parent class. D. You cannot invoke a method in superclass's parent class. 29 Which of the following statements are true? A. A method can be overloaded in the same class. B. A method can be overridden in the same class. C. If a method overloads another method, these two methods must have the same signature. D. If a method overrides another method, these two methods must have the same signature. E. A method in a subclass can overload a method in the superclass. 30 What is the output of the following code? new Person().printPerson(); new Student().printPerson(); class Student extends Person { public String getinfo() { return "Student"; class Person { public String getinfo() { return "Person"; public void printperson() { System.out.println(getInfo()); A. Person Person B. Person Student C. Stduent Student D. Student Person 31 Which of the following statements is false? Page 9 of 15

A. A public class can be accessed by a class from a different package. B. A private method cannot be accessed by a class in a different package. C. A protected method can be accessed by a subclass in a different package. D. A method with no visibility modifier can be accessed by a class in a different package. 32 are referred to as heavyweight components. A. AWT components B. Swing components C. GUI components D. Non-GUI components 33 The correct order of the following three statements is. 1. frame.setlocationrelativeto(null); 2. frame.setsize(100, 200); 3. frame.setvisible(true); A. 1 2 3 B. 1 3 2 C. 2 1 3 D. 3 2 1 34 Suppose a JFrame uses the GridLayout(0, 2). If you add six buttons to the frame, how many columns are displayed? A. 1 B. 2 C. 3 D. 4 35 creates a color object. A. new Color(0, 0, 0) B. new Color(0, 266, 0) C. new Color(255, 255, 255) D. new Color(1, 2, 3) 36 To add a component c to a JPanel p, use. A. p.add(c) B. p.getcontentpane(c) C. p.insert(c) D. p.append(c) Page 10 of 15

37 Which of the following is not an advantage of Java exception handling? A. Java separates exception handling from normal processing tasks. B. Exception handling improves performance. C. Exception handling makes it possible for the caller's caller to handle the exception. D. Exception handling simplifies programming because the error-reporting and error-handling code can be placed at the catch block. 38 Which of the following statements are true? A. You use the keyword throws to declare exceptions in the method heading. B. A method may declare to throw multiple exceptions. C. To throw an exception, use the key word throw. D. If a checked exception occurs in a method, it must be either caught or declared to be thrown from the method. 39 An instance of describes the errors caused by your program and external circumstances. These errors can be caught and handled by your program. A. RuntimeException B. Exception C. Error D. Throwable E. NumberFormatException 40 Which of the following declares an abstract method in an abstract Java class? A. public abstract method(); B. public abstract void method(); C. public void abstract Method(); D. public void method() { E. public abstract void method() { 41 Which of the following statements regarding abstract methods are true? A. Abstract classes have constructors. B. A class that contains abstract methods must be abstract. C. It is possible to declare an abstract class that contains no abstract methods. D. An abstract method cannot be contained in a nonabstract class. E. A data field can be declared abstract. Page 11 of 15

42 Show the output of running the class Test in the following code lines: interface A { class C { class B extends D implements A { public class Test extends Thread { B b = new B(); if (b instanceof A) System.out.println("b is an instance of A"); if (b instanceof C) System.out.println("b is an instance of C"); class D extends C { A. Nothing. B. b is an instance of A. C. b is an instance of C. D. b is an instance of A followed by b is an instance of C. 43 Suppose a button jbt is placed in a frame, the coordinate of the button within the content pane of the frame is. A. (jbt.getx(), jbt.gety()) B. (jbt.x, jbt.y) C. cannot be obtained D. (0, 0) 44 You should override the method to draw things on a Swing component. A. repaint() B. update() C. paintcomponent() D. init() 45 Which of the following statements are true? A. You may create a Graphics object using new Graphics(). B. Whenever a GUI component is displayed, its Graphics object is automatically created. C. The paintcomponent method is automatically invoked by the JVM. You should never invoke it directly. D. Invoking repaint() causes paintcomponent to be invoked by the JVM. Page 12 of 15

46 Which of the following statements are correct? A. You can set an image on a label, but the image is not resizable. B. You can set an image on a button, but the image is not resizable. C. You can draw an image on a GUI component using the drawimage method in the Graphics object. This image is resizable. 47 Clicking the closing button on the upper-right corner of a frame generates a(n) event. A. ItemEvent B. WindowEvent C. MouseMotionEvent D. ComponentEvent E. ContainerEvent 48 Which of the following statements are true? A. Each event class has a corresponding listener interface. B. The listener object's class must implement the corresponding event-listener interface. C. A source may have multiple listeners. D. The listener object must be registered by the source object. 49 To get the x coordinate of the mouse pointer for the MouseEvent evt, you use. A. evt.getx() B. evt.getpoint().x C. Either A or B D. Neither A nor B 50 Analyze the following code: public class Test implements Runnable { Thread t = new Thread(this); t.start(); public void run() { System.out.println("test"); A. The program does not compile because this cannot be referenced in a static method. B. The program compiles fine, but it does not print anything because t does not invoke the run() method. C. The program compiles and runs fine and displays test on the console. D. None of the above. Page 13 of 15

Section II [Total 30] You should attempt all section II (questions 2, 3, and 4) Q(2): write a program that displays a message in a panel, and uses two buttons to move the message on the panel to the left or right as shown in Figure 1. [12 Marks] Q(3): (Creating four fans) Write a program that places four fans in a frame of GridLayout with two rows and two columns, as shown in Figure 2. [12 Marks] Figure 1 Figure 2 Q(4): Write a problem that prompts the user to enter a string and reports whether the string is a palindrome. Note that (palindrome if it reads the same forward and backward). [6 Marks] Page 14 of 15 Good Luck

Section I [Total 60] Q(1): Multiple choice questions Section I : Key answer for the multiple choice questions Questions 1 2 3 4 5 6 7 8 9 10 Questions 11 12 13 14 15 16 17 18 19 20 Questions 21 22 23 24 25 26 27 28 29 30 Questions 31 32 33 34 35 36 37 38 39 40 Questions 41 42 43 44 45 46 47 48 49 50 Page 15 of 15