0% found this document useful (0 votes)
1K views8 pages

OOP Final 2

This document contains instructions for a final exam in Object-Oriented Programming with Java. It is divided into 5 parts worth a total of 40 points: 1. Short answer questions worth 6 points 2. Multiple choice questions worth 4.5 points 3. Finding and correcting errors in code worth 3 points 4. Determining output of code examples worth 5 points 5. Coding exercises worth 21.5 points involving inheritance, interfaces, exceptions handling, and file I/O.

Uploaded by

Desyilal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views8 pages

OOP Final 2

This document contains instructions for a final exam in Object-Oriented Programming with Java. It is divided into 5 parts worth a total of 40 points: 1. Short answer questions worth 6 points 2. Multiple choice questions worth 4.5 points 3. Finding and correcting errors in code worth 3 points 4. Determining output of code examples worth 5 points 5. Coding exercises worth 21.5 points involving inheritance, interfaces, exceptions handling, and file I/O.

Uploaded by

Desyilal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Adama science and Technology University

School of Engineering
Department of Computing
Object-Oriented Programming with Java (EEng 2301):
Final Exam (50%)

Time allotted: 2:30hrs


Wednesday, February 6, 2013 2:00PM

Student Information:

Name: ____________________

ID NO: ________________

Department: _______________

Group: _________________

Instructor Name: (Underline)

Endale/ Getamesay /Genet

Only For office use

Part I(6) II(4.5) III (3) IV (5) V (21.5) Total (40%)

Mark

1
Part I : Short answer (6 points)
1. What is difference between a class and Interface (2 points)

2. Compare and contrast between declaring a instance variable as protected compare to private access
modifier (2 point)

3. What is polymorphism? Describe with an example (2 point)

2
Part II: Multiple choice: circle the correct answer (1.5 point each)

1. Which of the following statements is false?


a) A superclass object is a subclass object but the reverse is not true
b) The class following the extends keyword in a class declaration is the direct superclass of the
class being declared.
c) A subclass is generally larger than its superclass
d) None
2. The throws clause of a method:
a. specifies the exceptions a method throws.
b. specifies the exceptions a method catches.
c. specifies the exceptions thrown by the calling method.
d. specifies the exceptions a method throws and catches.

3. What does the following statement do?


Scanner scanner = new Scanner( new File( "test.txt" ) );
a. Opens a binary file for input.
b. Opens a binary file for output.
c. Opens a text file for input.
d. Opens a text file for output.

Part III: Find the error(s) and correct it if there is any in following program (3 points)

no Program Your correction, if any


1 abstract class Shape {
2 callme(){
3 System.out.println(“the value of count in class “);}
4 abstract void display();
5 }
6 class Rect extends Shape{
7 int x, y ;
8 Rect(){}
9 }
10 public class AbstractDemoTest{
11 public static void main(String args[]) {
12 Shape s = new Shape();
13 }
14 }

Part IV: Output ( 5 points )

3
1. What is the output of this program (3 points)
class Vehicle {
static String Model= "BMW";
static double Price= 250000.0;
Vehicle () {}
public static String tostring() {
return ( "Model =" + Model + "Price " + Price ); }
}
//=====================================
class Car extends Vehicle {
static String Manufacturer= "Toyota";
Car() {}
public static String tostring(){

2. What is the output of the following code (2 points)


class Output {
static int x, y;
public static void main(String args[]) {
int array[] = {1,2,5,8};
try {

System.out.println(y);
array[4] = 20;
y = 42 / x;
System.out.println(array[4]);
}
catch (ArithmeticException e) {
System.out.println("Divide by 0" ); }
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(" Array index out of bound ");}
finally {
System.out.println(" the program finished!");}
}
}

Part V: Coding (21.5 points)


Class Name Variable Methods

student Full Name, Dorm No and school Tostring which returns full
information of a student

Student President Full Name, Dorm No and salary getpayment which returns salary of
the student president

1. Given the above information, by applying the concept of inheritance, write the full java program for
each class. )(5 points)
Hint:
o Identify the super and sub class
o Use constructor to initialize the instance variables
4
o Create a test class called TestStudent
o Create one object for each of the above class within the TestStudent class
o Display the salary of each object using the getpayment() method of each classes)…

5
2. Given an interface
interface circle {
final double pi= 3.142;
double computArea();
}
Create a class cylinder to implement an interface circle. The area of a cylinder is the product of Pi ,
radius square, and height of the cylinder.(3 points)

6
3. Create a class called Book with Title and Price as instance variables, and a method called
SaveToTextFile. Within the body of this method, write all the necessary line of instructions so as to
accept four books information from the keyboard and store them into the text file (c:\Books.txt).
(5points)

7
4. Write a class called Invoice with unit price and total quantity as instance variable and a method
called totalPay .The code within this method must accept the value for unit price and total quantity
variable from the keyboard and return the quotient (division) total quantity over unit price variables.
In addition to this, Within this method include all the possible exceptions handle issues (like input
mismatch, negative value for price and quantity… ) (5points) (hint define your exceptions to handle
negative price )

You might also like