100% found this document useful (1 vote)
14 views6 pages

SAMPLE

This document is a sample midterm exam for the Cen213 - Object Oriented Programming course at Epoka University. It includes multiple-choice questions, true/false statements, and coding exercises related to Java programming concepts. The exam assesses knowledge of Java syntax, data types, control structures, and object-oriented programming principles.

Uploaded by

cowen89070
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
100% found this document useful (1 vote)
14 views6 pages

SAMPLE

This document is a sample midterm exam for the Cen213 - Object Oriented Programming course at Epoka University. It includes multiple-choice questions, true/false statements, and coding exercises related to Java programming concepts. The exam assesses knowledge of Java syntax, data types, control structures, and object-oriented programming principles.

Uploaded by

cowen89070
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/ 6

Epoka University Sample Midterm Exam

Cen213 - Object Oriented Programming

Question 1: (5x1=5 points)


In each of the blanks below, write True if the statement beside the blank is true, False otherwise.

1.A public top-level Java class may be defined in a source file with any base name as long as the
file extension is .java. __________
2. Java identifiers can contain letters, digits, and the underscore symbol and may start with a
digit.________
3. In Java, char is a primitive data type, while String is an object data type. ___________
4. Java is a strongly typed language; therefore you must declare a data type for all variables.
_____________
5. You’re designing banking software and need to store 10000 customer accounts with
information on the accountholder’s name, balance, and interest rate. The best approach is store
30000 separate variables in the main method. __________________

Question 2: (10x1=10 points)


In the following questions circle the letter of the correct alternative. There is only one correct
alternative.

1.Which statement will produce the output: 2, 4, 6, 8, 10?


a) for (int i = 0; i < 8; i += 2) {System.out.print(i + " ");}
b) for (int i = 0; i < 10; i += 2) {System.out.print(i + " ");}
c) for (int i = 1; i < 10; i += 2) {System.out.print(i + " ");}
d) for (int i = 2; i <= 10; i += 2) {System.out.print(i + " ");}

2.What is the output of the following code?

String s1 = "Hello";
String s2 = "Welcome!";
s1 = s2;
System.out.println("s1: " +s1);
System.out.println("s2: " +s2);

a) s1: Hello
s2: Hello

b) s1: Welcome!
s2: Hello
c) s1: Welcome!
s2: Welcome!

d) s1: Hello
s2: Welcome!

3.What is the output?


int[] arr = new int[1];
arr[0] = 10;
System.out.println(arr[0]);

a) 10
b) 0
c) 1
d) ArrayIndexOutOfBoundsException

4.What is the output?


public static void main(String args[])
{
int x = 100;
int y = x;
y++;
System.out.println("Value of x is " + x);
System.out.println("Value of y is " + y);
}

a) Value of x is 0 Value of y is 1
b) Value of x is 100 Value of y is 1
c) Value of x is 100 Value of y is 1
d) Value of x is 100 Value of y is 101

5.Which of the following specifies accessibility to variables, methods, and classes?


a) Methods
b) Parameters
c) Overload constructors
d) Access modifiers
6.What is the output of the following lines of code?
int j=7,k=5,m=8,result; result=j/m*k; System.out.println(result);
a) 0 b) 4.375 c) 0.175 d) 280

7.Which of the following is not a legal name for a variable?


a) R2d2
b) dgo2sleep
c) 4geeks
d) to_be_or_not_to_be

8.Which of the following declares a one dimensional array named "score" of type int that can
hold 9 values?
a) int score;
b) int[] score;
c) int[] score=new int[9];
d) int score=new int[9];

9. Consider the following code snippet. What is printed?

a) 55555
b) 87668
c) AtlanticPacificIndianArcticSouthern
d) An ArrayIndexOutofBoundsException is thrown.

10. How would you use the ternary operator to rewrite this if statement?
if (gender == "male")
System.out.print("Mr.");
else
System.out.print("Ms.");
a) System.out.print( (gender == "male") ? "Mr." : "Ms." );
b) System.out.print( (gender == "male") ? "Ms." : "Mr." );
c) (gender == "male") ? "Mr." : "Ms." ;
d) (gender == "male") ? "Ms." : "Mr." ;

Question 3: (4 points)

What is printed when main is executed? Briefly argue your answer.

public class Test1


{
public static void main ( String [] args )
{ char c = 'b';
String s0 = " Hello World ";
switch (c)
{
case 'a':
System . out. println ("c = a");
case 'b':
System . out. println ("c = b");
case 'c':
System . out. println ("c = c");
case 'd':
System . out. println ("c = d");
default :
System . out. println ("c is not a, b, c, or d");
}
s0. toLowerCase ();
if (s0. equals (" hello world "))
System . out. println (" hiya Mars ");
else
System . out. println ("s0 doesn 't say hello world ... ");
for (int i = 0; i < 30; i++)
if (i % 3 == 0)
{
System .out . print (i + ", ");
}
}
}
Question 4: (7 points)
Write a Java program that find all pairs of elements in an array whose sum is equal to a specified
number. The program should ask capacity of array, array elements and the specified number from
the user, create the array and print all pairs of elements of the array whose sum is equal to the
specified number.

Question 5: (4 points)
The class Employee referres to an entity that consists of attributes such as : emp_id, emp_name
and emp_salary. This class has:
• the default constructor and another appropriate constructor that accepts all three
properties of an employee
• getters and setters methods for these properties
• calculateSalary() method that will change the salary in the condition of: if the salary of
employee is in the range 1000 $ ≤ salary ≤ 5000$ than the salary will increment with 2
%
• the method toString which will return a String composed of values of id, name and
salary of employee.
Complete the empty places denoted by …….. in the Employee class.
public class Employee {
private String emp_id;
private String emp_name;
private int emp_salary;
public Employee() {
this.emp_id= 0;
this.emp_name= “”;
this.emp_salary=0;
}

public Employee(String id, String name, int salary) {


…………..
}

public void setId(String id) {


………
}
public void setName(……………….) {
………………
}
public void setSalary(int salary) {
emp_salary= salary;
}
public String getId() {
……………………
}
public String getName() {
return emp_name;
}
public ……….. getSalary() {
………………………………
}

public void calculateSalary() {

………………………………………………………………
}

public String toString()


{
……………………………………………………..
}
}

You might also like