SlideShare a Scribd company logo
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 
Final Answer: 
Question 2: Which is these pairs represents the HAS-A relationship? 
A. bird/duck B. bird/fly 
C. bird/beak D. bird/flying animal 
Final Answer: 
Question 3: Which is these pairs represents the BEHAVES-LIKE relationship? 
A. bird/duck B. bird/fly 
C. bird/beak D. bird/flying animal 
Final Answer: 
Question 4: Which phrase below best describes the relationship between Country and Capital? 
A. IS-A B. HAS-A 
C. USES D. BEHAVES-LIKE 
Final Answer: 
Question 5: Which Java technology best supports the IS-A relationship? 
A. Inheritance B. Access Restriction 
C. Strong Typing D. Garbage Collection 
Final Answer: 
Question 6: Which Java keyword is used to specify inheritance? 
A. extends B. implements 
C. public D. static 
Final Answer: 
1
Question 7: Which Java keyword is used to specify compliance with an interface? 
A. extends B. implements 
C. public D. static 
Final Answer: 
Question 8: Which Java keywords can not appear in a class declaration? 
A. extends B. private 
C. void D. abstract 
Final Answer: 
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. 
Final Answer: 
Question 10: Are private classes only for malicious corporations closely guarding their propri-etary 
code? 
A. Yes B. No 
C. D. 
Final Answer: 
Question 11: Which Java keywords can not appear in instance variable definitions? 
A. extends B. protected 
C. int D. private 
Final Answer: 
Question 12: Which Java keywords can not appear in method definitions? 
A. implements B. void 
C. static D. private 
Final Answer: 
Question 13: Which of these fragments represents the HAS-A relationship between Foo and 
Bar? 
A. class Foo extends Bar{} B. class Foo implements Bar{ } 
C. class Foo { private Bar mybar; } D. abstract class Bar extends Foo{ } 
Final Answer: 
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); 
Final Answer: 
Question 15: What do the ’public’ and ’private’ keywords relate to? 
A. Typing B. Garbage Collection 
C. Polymorphism D. Access Restriction 
Final Answer: 
Question 16: Which Java technologies most powerfully supports the programming concept of 
“encapsulation”? 
A. Container Classes B. Access Restriction 
C. Garbage Collection D. Typing 
Final Answer: 
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 
Final Answer: 
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

More Related Content

What's hot

Embedded SW Interview Questions
Embedded SW Interview Questions Embedded SW Interview Questions
Embedded SW Interview Questions PiTechnologies
 
Structure and Enum in c#
Structure and Enum in c#Structure and Enum in c#
Structure and Enum in c#
Prasanna Kumar SM
 
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 1
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 1 UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 1
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 1
Knowledge Center Computer
 
Input processing and output in Python
Input processing and output in PythonInput processing and output in Python
Input processing and output in Python
Raajendra M
 
Handout#05
Handout#05Handout#05
Handout#05
Sunita Milind Dol
 
C++
C++C++
C++k v
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and comments
Nilimesh Halder
 
CBSE 12 ip 2018 sample paper
CBSE 12 ip 2018 sample paperCBSE 12 ip 2018 sample paper
CBSE 12 ip 2018 sample paper
Knowledge Center Computer
 
11 Unit 1 Chapter 03 Data Handling
11   Unit 1 Chapter 03 Data Handling11   Unit 1 Chapter 03 Data Handling
11 Unit 1 Chapter 03 Data Handling
Praveen M Jigajinni
 
Handout#03
Handout#03Handout#03
Handout#03
Sunita Milind Dol
 
Compiler lec 8
Compiler lec 8Compiler lec 8
Compiler lec 8
Ramadan Babers, PhD
 
Chapter 9 python fundamentals
Chapter 9 python fundamentalsChapter 9 python fundamentals
Chapter 9 python fundamentals
Praveen M Jigajinni
 
Programming construction tools
Programming construction toolsProgramming construction tools
Programming construction tools
sunilchute1
 
Literals,variables,datatype in C#
Literals,variables,datatype in C#Literals,variables,datatype in C#
Literals,variables,datatype in C#
Prasanna Kumar SM
 
Python Quiz Questions.docx
Python Quiz Questions.docxPython Quiz Questions.docx
Python Quiz Questions.docx
RMani7
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
Soran University
 
9608 Computer Science Cambridge International AS level Pre-Release May June p...
9608 Computer Science Cambridge International AS level Pre-Release May June p...9608 Computer Science Cambridge International AS level Pre-Release May June p...
9608 Computer Science Cambridge International AS level Pre-Release May June p...
Isham Rashik
 
Oop r&amp;s may 2019
Oop r&amp;s may 2019Oop r&amp;s may 2019
Oop r&amp;s may 2019
ktuonlinenotes
 
Oop december 2018
Oop december 2018Oop december 2018
Oop december 2018
ktuonlinenotes
 

What's hot (19)

Embedded SW Interview Questions
Embedded SW Interview Questions Embedded SW Interview Questions
Embedded SW Interview Questions
 
Structure and Enum in c#
Structure and Enum in c#Structure and Enum in c#
Structure and Enum in c#
 
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 1
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 1 UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 1
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 1
 
Input processing and output in Python
Input processing and output in PythonInput processing and output in Python
Input processing and output in Python
 
Handout#05
Handout#05Handout#05
Handout#05
 
C++
C++C++
C++
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and comments
 
CBSE 12 ip 2018 sample paper
CBSE 12 ip 2018 sample paperCBSE 12 ip 2018 sample paper
CBSE 12 ip 2018 sample paper
 
11 Unit 1 Chapter 03 Data Handling
11   Unit 1 Chapter 03 Data Handling11   Unit 1 Chapter 03 Data Handling
11 Unit 1 Chapter 03 Data Handling
 
Handout#03
Handout#03Handout#03
Handout#03
 
Compiler lec 8
Compiler lec 8Compiler lec 8
Compiler lec 8
 
Chapter 9 python fundamentals
Chapter 9 python fundamentalsChapter 9 python fundamentals
Chapter 9 python fundamentals
 
Programming construction tools
Programming construction toolsProgramming construction tools
Programming construction tools
 
Literals,variables,datatype in C#
Literals,variables,datatype in C#Literals,variables,datatype in C#
Literals,variables,datatype in C#
 
Python Quiz Questions.docx
Python Quiz Questions.docxPython Quiz Questions.docx
Python Quiz Questions.docx
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
9608 Computer Science Cambridge International AS level Pre-Release May June p...
9608 Computer Science Cambridge International AS level Pre-Release May June p...9608 Computer Science Cambridge International AS level Pre-Release May June p...
9608 Computer Science Cambridge International AS level Pre-Release May June p...
 
Oop r&amp;s may 2019
Oop r&amp;s may 2019Oop r&amp;s may 2019
Oop r&amp;s may 2019
 
Oop december 2018
Oop december 2018Oop december 2018
Oop december 2018
 

Similar to T1

Questões de Certificação SCJP
Questões de Certificação SCJPQuestões de Certificação SCJP
Questões de Certificação SCJP
José Maria Silveira Neto
 
1z0 804 exam-java se 7 programmer ii
1z0 804 exam-java se 7 programmer ii1z0 804 exam-java se 7 programmer ii
1z0 804 exam-java se 7 programmer ii
Isabella789
 
Indus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answersIndus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answers
Sushant Choudhary
 
Java Programming.pdf
Java Programming.pdfJava Programming.pdf
Java Programming.pdf
RavinderKSingla
 
Interfaces c#
Interfaces c#Interfaces c#
Interfaces c#
Nipam Medhi
 
Core java
Core javaCore java
Core java
prabhatjon
 
Inheritance and interface
Inheritance and interfaceInheritance and interface
Inheritance and interface
Shubham Sharma
 
E5
E5E5
E5
lksoo
 
Grade 11 CS Review (unit 1)
Grade 11 CS Review (unit 1)Grade 11 CS Review (unit 1)
Grade 11 CS Review (unit 1)kcardinale113
 
Cs141 mid termexam v1
Cs141 mid termexam v1Cs141 mid termexam v1
Cs141 mid termexam v1
Fahadaio
 
Gsp 125 Education Organization -- snaptutorial.com
Gsp 125   Education Organization -- snaptutorial.comGsp 125   Education Organization -- snaptutorial.com
Gsp 125 Education Organization -- snaptutorial.com
DavisMurphyB85
 
GSP 125 Enhance teaching/tutorialrank.com
 GSP 125 Enhance teaching/tutorialrank.com GSP 125 Enhance teaching/tutorialrank.com
GSP 125 Enhance teaching/tutorialrank.com
jonhson300
 
GSP 125 Effective Communication/tutorialrank.com
 GSP 125 Effective Communication/tutorialrank.com GSP 125 Effective Communication/tutorialrank.com
GSP 125 Effective Communication/tutorialrank.com
jonhson282
 
GSP 125 Enhance teaching - snaptutorial.com
GSP 125   Enhance teaching - snaptutorial.comGSP 125   Enhance teaching - snaptutorial.com
GSP 125 Enhance teaching - snaptutorial.com
DavisMurphyA81
 
GSP 125 Exceptional Education - snaptutorial.com
GSP 125 Exceptional Education - snaptutorial.comGSP 125 Exceptional Education - snaptutorial.com
GSP 125 Exceptional Education - snaptutorial.com
donaldzs162
 
GSP 125 Education Specialist / snaptutorial.com
  GSP 125 Education Specialist / snaptutorial.com  GSP 125 Education Specialist / snaptutorial.com
GSP 125 Education Specialist / snaptutorial.com
stevesonz146
 
Gsp 125 Massive Success / snaptutorial.com
Gsp 125  Massive Success / snaptutorial.comGsp 125  Massive Success / snaptutorial.com
Gsp 125 Massive Success / snaptutorial.com
NorrisMistryzo
 

Similar to T1 (20)

Questões de Certificação SCJP
Questões de Certificação SCJPQuestões de Certificação SCJP
Questões de Certificação SCJP
 
1
11
1
 
Ppl home assignment_unit3
Ppl home assignment_unit3Ppl home assignment_unit3
Ppl home assignment_unit3
 
1z0 804 exam-java se 7 programmer ii
1z0 804 exam-java se 7 programmer ii1z0 804 exam-java se 7 programmer ii
1z0 804 exam-java se 7 programmer ii
 
Indus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answersIndus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answers
 
Java Programming.pdf
Java Programming.pdfJava Programming.pdf
Java Programming.pdf
 
Interfaces c#
Interfaces c#Interfaces c#
Interfaces c#
 
Core java
Core javaCore java
Core java
 
Inheritance and interface
Inheritance and interfaceInheritance and interface
Inheritance and interface
 
E5
E5E5
E5
 
Grade 11 CS Review (unit 1)
Grade 11 CS Review (unit 1)Grade 11 CS Review (unit 1)
Grade 11 CS Review (unit 1)
 
Cs141 mid termexam v1
Cs141 mid termexam v1Cs141 mid termexam v1
Cs141 mid termexam v1
 
Gsp 125 Education Organization -- snaptutorial.com
Gsp 125   Education Organization -- snaptutorial.comGsp 125   Education Organization -- snaptutorial.com
Gsp 125 Education Organization -- snaptutorial.com
 
C++ questions
C++ questionsC++ questions
C++ questions
 
GSP 125 Enhance teaching/tutorialrank.com
 GSP 125 Enhance teaching/tutorialrank.com GSP 125 Enhance teaching/tutorialrank.com
GSP 125 Enhance teaching/tutorialrank.com
 
GSP 125 Effective Communication/tutorialrank.com
 GSP 125 Effective Communication/tutorialrank.com GSP 125 Effective Communication/tutorialrank.com
GSP 125 Effective Communication/tutorialrank.com
 
GSP 125 Enhance teaching - snaptutorial.com
GSP 125   Enhance teaching - snaptutorial.comGSP 125   Enhance teaching - snaptutorial.com
GSP 125 Enhance teaching - snaptutorial.com
 
GSP 125 Exceptional Education - snaptutorial.com
GSP 125 Exceptional Education - snaptutorial.comGSP 125 Exceptional Education - snaptutorial.com
GSP 125 Exceptional Education - snaptutorial.com
 
GSP 125 Education Specialist / snaptutorial.com
  GSP 125 Education Specialist / snaptutorial.com  GSP 125 Education Specialist / snaptutorial.com
GSP 125 Education Specialist / snaptutorial.com
 
Gsp 125 Massive Success / snaptutorial.com
Gsp 125  Massive Success / snaptutorial.comGsp 125  Massive Success / snaptutorial.com
Gsp 125 Massive Success / snaptutorial.com
 

More from lksoo

Lo48
Lo48Lo48
Lo48
lksoo
 
Lo43
Lo43Lo43
Lo43
lksoo
 
Lo39
Lo39Lo39
Lo39lksoo
 
Lo37
Lo37Lo37
Lo37
lksoo
 
Lo27
Lo27Lo27
Lo27
lksoo
 
Lo17
Lo17Lo17
Lo17
lksoo
 
Lo12
Lo12Lo12
Lo12
lksoo
 
T3
T3T3
T3
lksoo
 
T2
T2T2
T2
lksoo
 
T4
T4T4
T4
lksoo
 
P5
P5P5
P5
lksoo
 
P4
P4P4
P4
lksoo
 
P3
P3P3
P3
lksoo
 
P1
P1P1
P1
lksoo
 
P2
P2P2
P2
lksoo
 
L10
L10L10
L10
lksoo
 
L9
L9L9
L9
lksoo
 
L8
L8L8
L8
lksoo
 
L7
L7L7
L7
lksoo
 
L6
L6L6
L6
lksoo
 

More from lksoo (20)

Lo48
Lo48Lo48
Lo48
 
Lo43
Lo43Lo43
Lo43
 
Lo39
Lo39Lo39
Lo39
 
Lo37
Lo37Lo37
Lo37
 
Lo27
Lo27Lo27
Lo27
 
Lo17
Lo17Lo17
Lo17
 
Lo12
Lo12Lo12
Lo12
 
T3
T3T3
T3
 
T2
T2T2
T2
 
T4
T4T4
T4
 
P5
P5P5
P5
 
P4
P4P4
P4
 
P3
P3P3
P3
 
P1
P1P1
P1
 
P2
P2P2
P2
 
L10
L10L10
L10
 
L9
L9L9
L9
 
L8
L8L8
L8
 
L7
L7L7
L7
 
L6
L6L6
L6
 

Recently uploaded

Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 

Recently uploaded (20)

Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 

T1

  • 1. 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 Final Answer: Question 2: Which is these pairs represents the HAS-A relationship? A. bird/duck B. bird/fly C. bird/beak D. bird/flying animal Final Answer: Question 3: Which is these pairs represents the BEHAVES-LIKE relationship? A. bird/duck B. bird/fly C. bird/beak D. bird/flying animal Final Answer: Question 4: Which phrase below best describes the relationship between Country and Capital? A. IS-A B. HAS-A C. USES D. BEHAVES-LIKE Final Answer: Question 5: Which Java technology best supports the IS-A relationship? A. Inheritance B. Access Restriction C. Strong Typing D. Garbage Collection Final Answer: Question 6: Which Java keyword is used to specify inheritance? A. extends B. implements C. public D. static Final Answer: 1
  • 2. Question 7: Which Java keyword is used to specify compliance with an interface? A. extends B. implements C. public D. static Final Answer: Question 8: Which Java keywords can not appear in a class declaration? A. extends B. private C. void D. abstract Final Answer: 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. Final Answer: Question 10: Are private classes only for malicious corporations closely guarding their propri-etary code? A. Yes B. No C. D. Final Answer: Question 11: Which Java keywords can not appear in instance variable definitions? A. extends B. protected C. int D. private Final Answer: Question 12: Which Java keywords can not appear in method definitions? A. implements B. void C. static D. private Final Answer: Question 13: Which of these fragments represents the HAS-A relationship between Foo and Bar? A. class Foo extends Bar{} B. class Foo implements Bar{ } C. class Foo { private Bar mybar; } D. abstract class Bar extends Foo{ } Final Answer: 2
  • 3. 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); Final Answer: Question 15: What do the ’public’ and ’private’ keywords relate to? A. Typing B. Garbage Collection C. Polymorphism D. Access Restriction Final Answer: Question 16: Which Java technologies most powerfully supports the programming concept of “encapsulation”? A. Container Classes B. Access Restriction C. Garbage Collection D. Typing Final Answer: 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 Final Answer: 3
  • 4. 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
  • 5. 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
  • 6. 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
  • 7. 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
  • 8. 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
  • 9. /** * Your add method here */ /** * Your static mult method here */ /** * Your static main here */ } 9
  • 10. 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