Object-Oriented Programming in Java



Similar documents
CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

Java Classes. GEEN163 Introduction to Computer Programming

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

J a v a Quiz (Unit 3, Test 0 Practice)

LAB4 Making Classes and Objects

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Part I. Multiple Choice Questions (2 points each):

CS170 Lab 11 Abstract Data Types & Objects

AP Computer Science Java Subset

History OOP languages Year Language 1967 Simula Smalltalk

Inheritance, overloading and overriding

Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For

Glossary of Object Oriented Terms

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction

Sample CSE8A midterm Multiple Choice (circle one)

1. Use the class definition above to circle and identify the parts of code from the list given in parts a j.

Crash Course in Java

CSE 1020 Introduction to Computer Science I A sample nal exam

Tutorial on Writing Modular Programs in Scala

CS1002: COMPUTER SCIENCE OO MODELLING & DESIGN: WEEK 5

SE 360 Advances in Software Development Object Oriented Development in Java. Polymorphism. Dr. Senem Kumova Metin

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

Basic Object-Oriented Programming in Java

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Java CPD (I) Frans Coenen Department of Computer Science

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

CSE 452: Programming Languages. Acknowledgements. Contents. Java and its Evolution

Chapter 5 Aspect Oriented Programming

Overview. Elements of Programming Languages. Advanced constructs. Motivating inner class example

Java is an Object-Oriented Language. As a language that has the Object Oriented feature, Java supports the following fundamental concepts:

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

Master of Sciences in Informatics Engineering Programming Paradigms 2005/2006. Final Examination. January 24 th, 2006

CS 111 Classes I 1. Software Organization View to this point:

Java Interview Questions and Answers

Moving from CS 61A Scheme to CS 61B Java

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

Introduction to Object-Oriented Programming

15-214: Principles of Software Construction 8 th March 2012

Fundamentals of Java Programming

AP Computer Science A - Syllabus Overview of AP Computer Science A Computer Facilities

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Java Cheatsheet. Tim Coppieters Laure Philips Elisa Gonzalez Boix

Software Testing. Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program.

Java Programming. Binnur Kurt Istanbul Technical University Computer Engineering Department. Java Programming. Version 0.0.

More on Objects and Classes

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

CS193j, Stanford Handout #10 OOP 3

JAVA - OBJECT & CLASSES

JAVA - INHERITANCE. extends is the keyword used to inherit the properties of a class. Below given is the syntax of extends keyword.

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Agenda. What is and Why Polymorphism? Examples of Polymorphism in Java programs 3 forms of Polymorphism

Introduction to Java. CS 3: Computer Programming in Java

Programming Languages CIS 443

The Java Virtual Machine and Mobile Devices. John Buford, Ph.D. Oct 2003 Presented to Gordon College CS 311

3 Pillars of Object-oriented Programming. Industrial Programming Systems Programming & Scripting. Extending the Example.

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Java (12 Weeks) Introduction to Java Programming Language

Introduction: Abstract Data Types and Java Review

Introduction to Programming

Object-Oriented Programming in Java: More Capabilities

Java applets. SwIG Jing He

Compiling Object Oriented Languages. What is an Object-Oriented Programming Language? Implementation: Dynamic Binding

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

Description of Class Mutation Mutation Operators for Java

Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 2 November 21, 2011 SOLUTIONS.

Object-Oriented Programming Lecture 2: Classes and Objects

D06 PROGRAMMING with JAVA. Ch3 Implementing Classes

CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Software Engineering Techniques

CompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement

Grundlæggende Programmering IT-C, Forår Written exam in Introductory Programming

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

Object Oriented Software Design

java Features Version April 19, 2013 by Thorsten Kracht

AP Computer Science A Syllabus

Yosemite National Park, California. CSE 114 Computer Science I Inheritance

AP Computer Science Java Mr. Clausen Program 9A, 9B

Introduction to Object-Oriented Programming

Object-Oriented Programming: Polymorphism

Java: overview by example

Contents. Java - An Introduction. Java Milestones. Java and its Evolution

Building Java Programs

Android Application Development Course Program

Java Programming Fundamentals

Konzepte objektorientierter Programmierung

Lecture J - Exceptions

Objective C and iphone App

Transcription:

Object-Oriented Programming in Java Quiz 1 Jan 10, 2001 Problem 1: Who wants to be a Java developer? (with apologies to Regis) Fill in your answer in the space provided. Question 1: Which is these word-pairs represents the IS-A relationship ( in English)? A. duck/bird B. bird/fly C. beak/bird D. bird/nest Question 2: Which is these pairs represents the HAS-A relationship? A. bird/duck B. bird/fly C. bird/beak D. bird/flying animal Question 3: Which is these pairs represents the BEHAVES-LIKE relationship? A. bird/duck B. bird/fly C. bird/beak D. bird/flying animal Question 4: Which phrase below best describes the relationship between Country and Capital? A. IS-A B. HAS-A C. USES D. BEHAVES-LIKE Question 5: Which Java technology best supports the IS-A relationship? A. Inheritance B. Access Restriction C. Strong Typing D. Garbage Collection Question 6: Which Java keyword is used to specify inheritance? A. extends B. implements C. public D. static 1

Question 7: Which Java keyword is used to specify compliance with an interface? A. extends B. implements C. public D. static Question 8: Which Java keywords can not appear in a class declaration? A. extends B. private C. void D. abstract Question 9: Is it possible to use the techniques of object oriented programming in a language that does not specifically support OOP? A. Yes B. No C. D. Question 10: Are private classes only for malicious corporations closely guarding their proprietary code? A. Yes B. No C. D. Question 11: Which Java keywords can not appear in instance variable definitions? A. extends B. protected C. int D. private Question 12: Which Java keywords can not appear in method definitions? A. implements B. void C. static D. private Question Bar? 13: Which of these fragments represents the HAS-A relationship between Foo and A. class Foo extends Bar B. class Foo implements Bar C. class Foo private Bar mybar; D. abstract class Bar extends Foo 2

Question 14: Which line of code in the following can be inserted in place of the comments, to perform the initialization described by the comments? public class T int r; int s; T(int x, int y) r = x; s = y; class S extends T int t; public S(int x, int y, int z) // insert here the code // that would do the correct initialization // r= x and s= y t=z; A. T(x, y); B. this(x, y); C. super(x, y); D. super(x, y, z); Question 15: What do the public and private keywords relate to? A. Typing B. Garbage Collection C. Polymorphism D. Access Restriction Question 16: Which Java technologies most powerfully supports the programming concept of encapsulation? A. Container Classes B. Access Restriction C. Garbage Collection D. Typing Question 17: Which Java technologies most powerfully support the programming concept of abstraction? A. Inheritance and Polymorphism B. Heap Allocation C. Garbage Collection D. Applets 3

Problem 2: Program Analysis: Short Answer Question 1: What are the values of i,a, and b after the following code fragment runs.? int i; int a=1; int b=0; for(i=0;i<10;i++) a = a * 2; b++; i = a = b = Question 2: What is the value of a after the following code fragment runs? int a=0; while(true) if(a > 20) break; a = a+1; a = Question 3: What three lines will the following code print out when compiled and run? public class Spindle public static void main(string[] args) int[] a = new int[] 1,2,3,4; int b = 5; int c =6; Fold.mutilate( a, b, c); System.out.println( a[0]); System.out.println( b); System.out.println( c ); class Fold static void mutilate( int[] a, int b, int c) a[0] = 7; b = 8; c = 9; line1: line2: line3: 4

Question 4: What does the class Test below print out if it is compiled and run? public class Test int x; Test(String s) this(); System.out.println(s); System.out.println("This"); Test(int x) this("is"); Test() System.out.println("a test."); public static void main(string[] args) int val = 2; Test t = new Test(val); Test prints out: 5

The next three short answer question use the following group of classes. * An interface with one method interface Face1 public void bar(); * A class with an accessor and method foo() class Class1 private int size = 0; private String name; Class1(String name) this.name = name; public String getname() return(name); public void foo() System.out.println( Class1.foo() ); * A class inheriting from Class1 class Class2 extends Class1 implements Face1 int size = 0; int x; Class2(String name) super(name); public void foo() System.out.println( Class2.foo() ); public void bar() System.out.println( Class2.bar() ); 6

Question 5: What does the following print out? public class TestClass public static void main(string[] args) Class1 c = new Class2( me ); c.foo(); Ans: Question 6: What does the following print out? public class TestClass public static void main(string[] args) Class1 c = new Class1( me ); c.foo(); Ans: Question 7: What does the following print out? public class TestClass public static void main(string[] args) Class2 c = new Class2( me ); System.out.println(c.getName()); Ans: Question 8: What does the following print out? public class TestClass public static void main(string[] args) Face1 c = new Class2( me ); c.bar(); Ans: 7

Problem 3: Class Implementation In this problem we ask you to implement part of a class Fraction, which represents fractions of the form a/b where a and b are integers, (1/2, 4/6, 101/432. etc.). In the space below, complete the class Fraction. Use int to store the numerator and denominator. Include a constructor that initializes from a numerator and denominator. Write an instance method for addition. [Hint: a/b + c/d = (ad + bc)/bd.] Write a static method for multiplication. [Hint: a/b c/d = ac/bd.] Write a static main() that allocates two Fractions, 1/2 and 3/4 and stores their sum in a third variable. (Be merciful to graders: please write clearly). * Class Fraction. Represent the fraction X/Y where X and Y are integers public class Fraction * Your instance vars here * Your constructor here Continued on next page 8

* Your add method here * Your static mult method here * Your static main here 9

Problem 4: OOP Design You are designing an OO program to help people plan an evening out. It is proposed that the following classes be used. Add inheritance ( extends phrases ) and instance variables to show the IS-A and HAS-A relationships between these classes. Do not introduce any additional classes or and instance variables of any basic type. [Note: By Business, we mean anything that would appear in the Yellow Pages]. class Address class Business class City class Restaurant class Theater 10