Questions Answer Key Questions Answer Key Questions Answer Key

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 Questions for Chapter 9

Practice for Chapter 11

Instruction to students:

Computer Programming, I. Laboratory Manual. Final Exam Solution

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

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

CS2401 QUIZ 5 February 26, questions / 20 points / 20 minutes NAME:..

Islamic University of Gaza Faculty of Engineering Computer Engineering Department

this keyword in java javatpoint

CS 113 PRACTICE FINAL

University of Palestine. Mid Exam Total Grade: 100

2 What are the differences between constructors and methods?

Programming in Java, 2e Sachin Malhotra Saurabh Choudhary

Java Class Design. Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding

CS1150 Principles of Computer Science Objects and Classes

Inheritance and Polymorphism

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

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

CONSTRUCTOR & Description. String() This initializes a newly created String object so that it represents an empty character sequence.

Chapter 1: Introduction to Computers, Programs, and Java

Class, Variable, Constructor, Object, Method Questions

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

Chapter 5 Object-Oriented Programming

Chapter 5. Inheritance

Object-Oriented Programming More Inheritance

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

Chapter 11 Inheritance and Polymorphism

What is Inheritance?

Announcements. PS 3 is due Thursday, 10/6. Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am

Chapter 10 Inheritance and Polymorphism. Dr. Hikmat Jaber

Answer1. Features of Java

Homework 6. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

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

Midterm Exam CS 251, Intermediate Programming March 6, 2015

Java Object Oriented Design. CSC207 Fall 2014

CS 112 Programming 2. Lecture 06. Inheritance & Polymorphism (1) Chapter 11 Inheritance and Polymorphism

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

Inheritance and Polymorphism

Mobile Application Development ( IT 100 ) Assignment - I

CS-202 Introduction to Object Oriented Programming

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

CS101 Part 2: Practice Questions Algorithms on Arrays, Classes and Objects, String Class, Stack Class

Object Oriented Programming in C#

Inheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods.

COMP200 - Object Oriented Programming: Test One Duration - 60 minutes

Tutorial 7. If it compiles, what does it print? Inheritance 1. Inheritance 2

Lecture 5: Methods CS2301

1 Shyam sir JAVA Notes

CISC 3115 TY3. C09a: Inheritance. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 9/20/2018 CUNY Brooklyn College

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

Midterm Exam CS 251, Intermediate Programming March 12, 2014

Full file at Chapter 2 - Inheritance and Exception Handling

ECE 122. Engineering Problem Solving with Java

Chapter 14 Abstract Classes and Interfaces

Java Fundamentals (II)

Lecture Notes Chapter #9_b Inheritance & Polymorphism

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

CMSC 132: Object-Oriented Programming II

CMSC 132: Object-Oriented Programming II

CS Week 13. Jim Williams, PhD

Inheritance (continued) Inheritance

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

Method Overriding in Java

Object Orientated Programming Details COMP360

Access and Non access Modifiers in Core Java Core Java Tutorial

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

QUIZ 2 Introduction to Computer Science (COMP 250) Mon. March 2, 2009 Professor Michael Langer

Chapter 6 Introduction to Defining Classes

Basics of Object Oriented Programming. Visit for more.

CO Java SE 8: Fundamentals

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

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L

24. Inheritance. Java. Fall 2009 Instructor: Dr. Masoud Yaghini

Midterm Exam CS 251, Intermediate Programming October 8, 2014

Chapter 4 Defining Classes I

The Essence of OOP using Java, Nested Top-Level Classes. Preface

22. Inheritance. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

CLASS DESIGN. Objectives MODULE 4

CS260 Intro to Java & Android 03.Java Language Basics

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Java: introduction to object-oriented features

Week 5-1: ADT Design

Introduction to Programming Using Java (98-388)

1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these. Answer: B

CS 116 Week 8 Page 1

Programming II (CS300)

Inf1-OP. Classes with Stuff in Common. Inheritance. Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein.

INHERITANCE Mrs. K.M. Sanghavi

Inheritance and Polymorphism. CSE 114, Computer Science 1 Stony Brook University

CIS 110: Introduction to computer programming

Exercise: Singleton 1

CS 113 MIDTERM EXAM 2 SPRING 2013

Method Overriding. Note that you can invoke the overridden method through the use of the keyword super.

Programming overview

Object-Oriented Programming Concepts

F I N A L E X A M I N A T I O N

Transcription:

Benha University Term: 2 nd (2013/2014) Class: 2 nd Year Students Subject: Object Oriented Programming Faculty of Computers & Informatics Date: 26/4/2014 Time: 1 hours Exam: Mid-Term (B) Name:. Status: Instruction to students: 1. You should attempt 25 out of the 30 MCQ questions. 2. Answer for the multiple choice questions should be written in the next table. 3. The exam paper is 10 pages long. Key answer for the multiple choice questions Questions 1 2 3 4 5 6 7 8 9 10 Answer Key Questions 11 12 13 14 15 16 17 18 19 20 Answer Key Questions 21 22 23 24 25 26 27 28 29 30 Answer Key Answer 25 Questions from the following questions: 1 Which of the following statements are true? (Choose two) A. To override a method, the method must be defined in the subclass using the same signature and compatible return type as in its superclass. B. Overloading a method is to provide more than one method with the same signatures. C. It is a compilation error if two methods differ only in return type in the same class. D. A private method can be overridden. If a method defined in a subclass is private in its superclass, the two methods are completely unrelated. 2 Analyze the following code: (Choose two) A a = new A(); a.print(); class A { String s; A(String s) { this.s = s; void print() { System.out.println(s); A. The program has a compilation error because class A is not a public class. Page 1 of 10

B. The program has a compilation error because class A does not have a default constructor. C. The program compiles and runs fine and prints nothing. D. The program would compile and run if you change A a = new A() to A a = new A("5"). 3 What is wrong in the following code? class TempClass { int i; public void TempClass(int j) { int i = j; public class C { TempClass temp = new TempClass(2); A. The program has a compilation error because TempClass does not have a default constructor. B. The program has a compilation error because TempClass does not have a constructor with an int argument. C. The program compiles fine, but it does not run because class C is not public. D. The program compiles and runs fine. 4 Analyze the following code. int x = 100; public Test(String t) { System.out.println(" Test"); Test test = new Test( OOP ); System.out.println(test.x); A. OOP 0 B. OOP 100 C. Test 100 D. The program has a compile error because Test does not have a default constructor. 5 Analyze the following code: double radius; final double PI= 3.15169; double area = radius * radius * PI; System.out.println("Area is " + area); A. The program has compile errors because the variable radius is not initialized. B. The program has a compile error because a constant PI is defined inside a method. C. The program has no compile errors but will get a runtime error because radius is not initialized. D. The program compiles and runs fine. Page 2 of 10

6 How many JFrame objects can you create and how many can you display? A. one B. two C. three D. unlimited 7 Variables that are shared by every instances of a class are. A. public variables B. private variables C. instance variables D. class variables 8 You should add the static keyword in the place of? in Line in the following code: 1 2 private int age; 3 public? int square(int n) { 4 return n * n; 5 6 public? int getage() { 7 A. in line 3 B. in line 6 C. in both line 3 and line 6 D. none 9 What is the printout of the second println statement in the main method? public class Foo { int i; static int s; Foo f1 = new Foo(); System.out.println("f1.i is " + f1.i + " f1.s is " + f1.s); Foo f2 = new Foo(); System.out.println("f2.i is " + f2.i + " f2.s is " + f2.s); Foo f3 = new Foo(); System.out.println("f3.i is " + f3.i + " f3.s is " + f3.s); public Foo() { i++; s++; A. f2.i is 1 f2.s is 1 B. f2.i is 1 f2.s is 2 C. f2.i is 2 f2.s is 2 D. f2.i is 2 f2.s is 1 Page 3 of 10

10 To prevent a class from being instantiated, A. don't use any modifiers on the constructor. B. use the public modifier on the constructor. C. use the private modifier on the constructor. D. use the static modifier on the constructor. 11 Analyze the following code: public static void main(string args[]) { NClass nc = new NClass(); nc.t = nc.t++; class NClass { int t; private NClass() { A. The program has a compilation error because the NClass class has a private constructor. B. The program does not compile because the parameter list of the main method is wrong. C. The program compiles, but has a runtime error because t has no initial value. D. The program compiles and runs fine. 12 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. 13 "abc".compareto("aba") returns. A. 1 B. 2 C. -1 D. -2 E. 0 Page 4 of 10

14 returns the last character in a StringBuilder variable named strbuf? A. strbuf.charat(strbuf.length() - 1) B. strbuf.charat(strbuf.capacity() - 1) C. StringBuilder.charAt(strBuf.length() - 1) D. StringBuilder.charAt(strBuf.capacity() - 1) 15 Which method can be used to create an input object for file temp.txt? A. new Scanner("temp.txt") B. new Scanner(temp.txt) C. new Scanner(new File("temp.txt")) D. new Scanner(File("temp.txt")) 16 What is the printout for the third println statement in the main method? public class Foo { static int i = 0; static int j = 0; int i = 2; int k = 3; { int j = 3; System.out.println("i + j is " + i + j); k = i + j; System.out.println("k is " + k); System.out.println("j is " + j); A. j is 0 B. j is 1 C. j is 2 D. j is 3 17 You can declare two variables with the same name in. A. a method one as a formal parameter and the other as a local variable B. a block C. two nested blocks in a method (two nested blocks means one being inside the other) D. different methods in a class 18 Which of the following can be placed in the blank line in the following code? private int id; public void m1() {.id = 45; Page 5 of 10

A. this B. Test 19 Which of the following can be placed in the blank line in the following code? private static int id; public static void m1() {.id = 45; A. this B. Test 20 Suppose you create a class Cylinder to be a subclass of Circle. Analyze the following code: class Cylinder extends Circle { double length; Cylinder(double radius) { Circle(radius); A. The program compiles fine, but you cannot create an instance of Cylinder because the constructor does not specify the length of the cylinder. B. The program has a compile error because you attempted to invoke the Circle class's constructor illegally. C. The program compiles fine, but it has a runtime error because of invoking the Circle class's constructor illegally. 21 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(); 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" Page 6 of 10

22 Object-oriented programming allows you to derive new classes from existing classes. This is called. A. encapsulation B. inheritance C. abstraction D. generalization 23 Which of the following statements are true? (Choose two) 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. 24 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 25 Invoking returns the number of the elements in an ArrayList x. A. x.getsize() B. x.getlength(0) C. x.length(1) D. x.size() 26 What modifier should you use on the members of a class so that they are not accessible to another class in a different package, but are accessible to any subclasses in any package? A. public B. private C. protected D. Use the default modifier. Page 7 of 10

27 Which of the following statements is false? 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. 28 What is the output of the following code? class Student{ int id; String name; Student (){System.out.println("default constructor is invoked"); Student(int id,string name){ this ();. this.id = id; this.name = name; void display(){system.out.println(id+" "+name); public static void main(string args[]){ Student e1 = new Student(111,"Ahmed"); Student e2 = new Student(222,"Moustafa"); e1.display(); e2.display(); A. default constructor is invoked default constructor is invoked 111 Ahmed 222 Moustafa B. default constructor is invoked 111 Ahmed 222 Moustafa C. 111 Ahmed 222 Moustafa 29 What is the output of the following code? class Vehicle{ int speed=50; class Bike extends Vehicle{ int speed=100; void display(){ System.out.println(super.speed); public static void main(string args[]){ Bike b=new Bike(); b.display(); Page 8 of 10

A. 100 B. 50 C. Compile Time Error 30 What is the output of the following code? class Person{ void message(){system.out.println("welcome"); class Student extends Person{ void message(){system.out.println("welcome to OOP"); void display(){ message(); super.message(); public static void main(string args[]){ Student s=new Student(); s.display(); A. welcome B. welcome to OOP welcome C. welcome to OOP Good Luck Draft Paper Page 9 of 10

Page 10 of 10