Islamic University of Gaza Faculty of Engineering Computer Engineering Department

Similar documents
Practice for Chapter 11

Questions Answer Key Questions Answer Key Questions Answer Key

CS-202 Introduction to Object Oriented Programming

Questions Answer Key Questions Answer Key Questions Answer Key

Java Object Oriented Design. CSC207 Fall 2014

Chapter 5 Object-Oriented Programming

Questions Answer Key Questions Answer Key Questions Answer Key

Class, Variable, Constructor, Object, Method Questions

CS 113 PRACTICE FINAL

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

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

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

CH. 2 OBJECT-ORIENTED PROGRAMMING

COMPUTER SCIENCE DEPARTMENT PICNIC. Operations. Push the power button and hold. Once the light begins blinking, enter the room code

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

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

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

Introduction to Programming Using Java (98-388)

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

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

Inheritance and Polymorphism

CS1150 Principles of Computer Science Objects and Classes

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

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

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

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

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

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Java Magistère BFA

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

JAVA MOCK TEST JAVA MOCK TEST II

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

Inheritance and Polymorphism

The software crisis. code reuse: The practice of writing program code once and using it in many contexts.

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U

Big software. code reuse: The practice of writing program code once and using it in many contexts.

Topic 7: Inheritance. Reading: JBD Sections CMPS 12A Winter 2009 UCSC

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

Chapter 5. Inheritance

Inheritance and object compatibility

Chapter 10 Inheritance and Polymorphism. Dr. Hikmat Jaber

CSC207H: Software Design. Java + OOP. CSC207 Winter 2018

Computer Programming, I. Laboratory Manual. Final Exam Solution

Object-Oriented Concepts

Java Fundamentals (II)

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

AP CS Unit 6: Inheritance Notes

Introduction to Inheritance

CS 251 Intermediate Programming Inheritance

Selected Questions from by Nageshwara Rao

Lecture 2: Java & Javadoc

Inheritance (continued) Inheritance

Object-Oriented Programming Concepts

25. Generic Programming

Lecture Notes Chapter #9_b Inheritance & Polymorphism

Inheritance (Part 5) Odds and ends

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

Chapter 1: Introduction to Computers, Programs, and Java

What is Inheritance?

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

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

STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes

Chair of Software Engineering Java and C# in Depth

Rules and syntax for inheritance. The boring stuff

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

Object- Oriented Analysis, Design and Programming

Chapter 14 Abstract Classes and Interfaces

1 Shyam sir JAVA Notes

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

Final Examination Semester 3 / Year 2008

Java and OOP. Part 3 Extending classes. OOP in Java : W. Milner 2005 : Slide 1

COMP 250: Java Object Oriented Programming

Distributed Systems Recitation 1. Tamim Jabban

ITI Introduction to Computing II

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

More about inheritance

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

Inheritance, Polymorphism, and Interfaces

CmSc 150 Fundamentals of Computing I. Lesson 28: Introduction to Classes and Objects in Java. 1. Classes and Objects

Lecture 4: Extending Classes. Concept

Compiler Errors. Flash CS4 Professional ActionScript 3.0 Language Reference. 1 of 18 9/6/2010 9:40 PM

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

Declarations and Access Control SCJP tips

ITI Introduction to Computing II

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods

More on inheritance CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2014

ITI Introduction to Computing II

Mobile Application Development ( IT 100 ) Assignment - I

Chapter 6 Introduction to Defining Classes

JAVA Programming Language Homework I - Nested Class

C++ Important Questions with Answers

Object Oriented Programming. Java-Lecture 11 Polymorphism

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

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

Lecture 36: Cloning. Last time: Today: 1. Object 2. Polymorphism and abstract methods 3. Upcasting / downcasting

Objects and Classes. 1 Creating Classes and Objects. CSCI-UA 101 Objects and Classes

CHAPTER 7 OBJECTS AND CLASSES

Transcription:

Student Mark Islamic University of Gaza Faculty of Engineering Computer Engineering Department Question # 1 / 18 Question # / 1 Total ( 0 ) Student Information ID Name Answer keys Sector A B C D E A B C D E F G H I J K L M Question Answers Table

A What is the printout of the following code public static void main(string [] args) { A p = new A(); System.out.println(p); Class A0 //System.exit(0); Class A0 System.out.println(p); int i; A() { String tostring() { return Class A + i; B What is the printout of the following code A p = new A(); A q = new A(); System.out.println(p.f()); System.out.println(q.f()); p = q = new A(); System.out.println(p.f()); System.out.println(q.f()); System.out.println(new A().f()); System.out.println(A.y); int x; static int y; A() { x = y; y++; int f() { return x; C What is the printout of the following code public public static void main(string[ ] args) { A a = new A( Welcome to Java ); a.print(); Welcome to Java String s; A(String s) { this.s = s; void print() { System.out.println(s); D What is the printout of the following code public static void main(string [] args){ A a = new A(); System.out.println(a.i + +a.f()); A a1 = new B(); System.out.println(a1.i+ +a1.f()); A a = (B)a1; System.out.println(a.i+ +a.f()); class B extend A{ int i = 8; int f(){ return ; int i = 9; int f(){ return 5; 9 5 9 9 0 1 4 E What is the printout of the following code { int p = 1, q = ; p = q; p = ; System.out.println(p); System.out.println(q); { A p = new A(1), q = new A(); p = q; p.f(); System.out.println(p.x); { int p = 4, q = 4; System.out.println(p == q); { A p = new A(4), q = new A(4); System.out.println(p == q); int x; A(int p) { f(p) ; void f(int p) { x = p; F What is the printout of the following code int p; A q; p=1; e(p); System.out.println(p); p=; f(p); System.out.println(p); p=; p=f(p); System.out.println(p); q = new A(); q.x = 4; g(q); q = new A(); q.x = 5; h(q); q = new A(); q.x = 6; q = h(q); static void e(int p) { p = 7; static int f(int p) { p = 8; return p; static void g(a p) { p = new A(); static A h(a p) { p.x = 10; return p; int x; true false 1 8 4 10 10 G What is the printout of the following code public public static void main(string[ ] args) { String s1 = Welcome to Java! ; String s = s1; if (s1 == s) System.out.println( s1 and s reference to the same String object ); else System.out.println( s1 and s reference to different String objects ); s1 and s reference to the same String object

H What is the printout of the following code A p = new A(new A(1),, new A(, new A(4))); p.z.f(5); p.f(6); System.out.println(A.g(p)); System.out.println(A.g(p.y)); System.out.println(A.g(p.z)); System.out.println(A.g(p.y.y)); System.out.println(A.g(p.z.z)); System.out.println(A.g(p.y.z)); int x; A y, z; A(int p) { x = p; A(int p, A q) { x = p; z = q; z.y = this; A(A p, int q, A r) { this(q, r); y = p; void f(int p) { new A(this, p, z); static int g(a p) { if (p == null) return 0; return p.x; 1 0 4 0 I What is the printout of the following code public public static void main (String args[]){ //System.out.println(new A()); A.print(); class A private A() { static void print(){ System.out.println( class A ); K What is the printout of the following code public public static void main( String args[] ) { C c = new C(); System.out.println(c.max(1,9)); class C extends B { 9 int max(int x, int y) { return super.max(x+10, y+10); class B extends A { int max(int x,int y) { return super.max(x,y) 10; int max(int x,int y) { if (x>y) return x; else return y; L What is the printout of the following code public A aa = new A("Test"); System.out.println(aa.f()); test System.out.println(aa); Test final private final String s; public A(String str) { this.s = str; String f() { return s.tolowercase(); public String tostring() { return this.s; J What is the printout of the following code public public static void main (String[] args) { StringBuffer a = new StringBuffer( Hello ); System.out.println(a.capacity()); a.ensurecapacity(0); 1 System.out.println(a.capacity()); 44 a.ensurecapacity(55); 90 System.out.println(a.capacity());

Question # : Choose the correct answer A.. represents an entity in the real world that can be distinctly identified. a) An object b) A data field c) An method d) A Class B Given the declaration Circle x = new Circle(), which of the following statement is most accurate? a) x contains an object of the Circle type. b) You can assign an int value to x. c) x contains an int value. d) x contains a reference to a Circle object. C Which of the following statements is most accurate? (Choose all that apply.) a) A reference variable is an object. b) An object may contain the references of other objects. c) An object may contain other objects. d) A reference variable refers to an object. D Variables that are shared by every instances of a class are.. a) public variables b) class variables c) instance variables d) private variables E To prevent a class from being instantiated,.. a) use the private modifier on the constructor. b) don't use any modifiers on the constructor. c) use the public modifier on the constructor. d) use the static modifier on the constructor. F Suppose s1 and s are two strings. Which of the following statements or expressions is incorrect? (Choose all that apply.) a) String s = s1 - s; b) char c = s1[0]; c) boolean b = s1.compareto(s); d) char c = s1.charat(s1.length()); G Assume s is "ABCABC", the method.. returns a new string "abcabc". a) s.replace('a', 'A') b) s.tolowercase() c) s.replace("abcabc", "abcabc") d) s.replace('a', 'a') H Which class do you use to read data into a text file? a) Scanner b) PrintWriter c) System d) File I Object-oriented programming allows you to derive new classes from existing classes. This is called.. a) abstraction b) encapsulation c) inheritance d) generalization J Which of the following statements are true? (Choose all that apply.) a) "Class A extends B" means B is a subclass of A. b) A subclass is usually extended to contain more functions and more detailed information than its superclass. c) "Class A extends B" means A is a subclass of B. d) A subclass is a subset of a superclass. K Polymorphism means.. a) that a variable of supertype can refer to a subtype b) that data fields should be declared private object c) that a class can extend another class d) that a class can contain another class

L Which of the following statements are true? (Choose all that apply.) a) Overloading a method is to provide more than one method with the same name but with different signatures to distinguish them. c) It is a compilation error if two methods differ only in return type in the same class. M e) A static method cannot be overridden. If a static method defined in the superclass is redefined in a subclass, the method defined in the superclass is hidden. Which of the following statements are true? (Choose all that apply.) b) A private method cannot be overridden. If a method defined in a subclass is private in its superclass, the two methods are completely unrelated. d) To override a method, the method must be defined in the subclass using the same signature and compatible return type as in its superclass. a) The compiler finds a matching method according b) Dynamic binding can apply to instance methods. to parameter type, number of parameters, and order of the parameters at compilation time. c) Dynamic binding can apply to static methods. d) You can always pass an instance of a subclass to a parameter of its superclass type. This feature is known as polymorphism. e) A method may be implemented in several subclasses. The Java Virtual Machine dynamically binds the implementation of the method at runtime. Good Luck

Practical Question Write a class named Book that keeps track of book objects such that the instance data contains the book s title and author and a unique identification number, say id that starts form 1 for the first book object and is incremented by 1 each time a new book with at least the title specified is created. The required methods in the Book class are as follows: constructors: One without parameters that sets the title and author to unknown and id to 0; one with a single parameter that sets the title to the given value as parameter, sets the author to unknown, increments the sequence by 1 and sets id to this sequence number; one with two parameters for title and author, setting the corresponding instance data, and id as in the second constructor. The setter methods for title and author. The getter methods for title, author, and id. The equals method that compares the current book object with another Book object given as a parameter and returns true if both objects have the same title and author properties, and false otherwise. The tostring method that returns a text including the book s title, author and id. Refer to the sample execution window for the test program for details. The getinitials method that returns the initial letters of the author s first name(s) and last name, if the author s name is known (not equal to unknown, or not null).assume that there can be at most two names and one surname separated by a single blank. The search method that return information based on book id; Write a driver class that tests the Book class. Allow the user to enter as many book objects as s/he wants. Take care of necessary object initializations. Store the first and last book objects separately. Print each book object. Compare the first and last book objects, if any, and display a proper message if they are the same. Display the last book s author s initials, if the user has input any valid book object. Test search method.