0% found this document useful (0 votes)
411 views4 pages

LDRP Mid Semester Exam: OOP with JAVA

This document contains a mid-semester exam for an Object Oriented Programming with Java course. The exam has three questions. Question 1 has five sub-questions that ask the student to determine output for code snippets involving modulus, Unicode characters, casting, constructor calls, and increment operators. Question 2 has three code snippets with errors and asks the student to identify and correct the errors. Question 3 [A] has two code snippets involving recursion to calculate Fibonacci numbers and to check for palindromes, with blanks to be filled in. Question 3 [B] asks the student to write a Java program demonstrating either partial interfaces or throwing a custom exception.

Uploaded by

Dhrumil Dancer
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)
411 views4 pages

LDRP Mid Semester Exam: OOP with JAVA

This document contains a mid-semester exam for an Object Oriented Programming with Java course. The exam has three questions. Question 1 has five sub-questions that ask the student to determine output for code snippets involving modulus, Unicode characters, casting, constructor calls, and increment operators. Question 2 has three code snippets with errors and asks the student to identify and correct the errors. Question 3 [A] has two code snippets involving recursion to calculate Fibonacci numbers and to check for palindromes, with blanks to be filled in. Question 3 [B] asks the student to write a Java program demonstrating either partial interfaces or throwing a custom exception.

Uploaded by

Dhrumil Dancer
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

KADI SARVA VISHWAVIDHYALAYA

LDRP Institute of Technology and Research


Mid Semester Examination – August - 2014
B.E. Semester V (CE/IT)

CE 505 / IT 505 Object Oriented Programming with JAVA

Date: 28/08/14 Max. Marks: 30


Time: 1.30 Hrs
Instruction: (1) Use of Scientific calculator is permitted.
(2) All questions are Compulsory.
(3) Figure to the right indicates full marks.

Q. I Give output of following code.


1. [Link](10.10%20); [1]
2. [Link]("\u0042"); [1]
3. double d = 323.142; [1]
byte b;
b = (byte) d;
[Link](“b = “ + b);
4. class gp { [3]
int a;
gp() { [Link](“GP-Default”); }
gp(int x) { [Link](“GP-Parameterised”); }
}
class parent extends gp {
parent() { [Link](“Parent-Default”); }
parent(int x) { [Link](“Parent-Parameterised”); }
}
class Demo {
public static void main(String ar[]) {
gp g1 = new gp(5);
parent p1 = new parent(10); }
}
5. class DemoPaper { [2]
public static void main(String ar[]) {
char ch1 = 65;
char ch2 = ch1++;
[Link](ch1 + “ ” + ch2);
}
}

Page 1 of 4
Q. II Find out error(s) if any in the following code and correct it.
1. class DemoPaper { [2]
public static void main(String ar[]) {
int a = 10;
{
int a = 20;
[Link](a);
}
[Link](a);
}
2. interface int1 { [3]
int a;
void put();
}
class myClass implements int1 {
void put() {
[Link](“Method Called”);
}
class DemoPaper {
public static void main(String ar[]) {
int1 c1 = new int1();
[Link]();
}
}
3. class gp { [2]
gp() {
[Link]("Default - GP");
}
gp(int x) {
[Link]("Parameterised - GP");
}
}
class p extends gp {
p() {
[Link]("Default - P");
}
p(int x) {
[Link]("Parameterised - P");
}
}
class child extends p {
child() {

Page 2 of 4
super(10);
[Link]("Default - child");
}
child(int x) {
[Link]("Parameterised - child");
}
}
class PaperDemo {
public static void main(String ar[]) {
child c = new child();
}
}
Q. III [A] Fill in the blanks such that program will generate expected [7]
output.
1. class FiboPaper {
public static void main(String args[]) {
int no = [Link](args[0]);
_________ . fibo(__ ,__ ,no);
}
_______ void fibo(int f1, int f2, int no) {
int f3;
if(no==0) {
return;
}
f3 = f1 + f2;
[Link]._________(f1 + " ");
fibo(___ ,____ ,____);
}
}
Expected Output:
3 5 8 13 21

OR

1. class PalindromPaper { [7]


________ int sum;
________ boolean b = true;
public static void main(String args[]) {
int no = [Link](args[0]);
_____________ . peli(no,________);
if(_____)
[Link]("Palindrom");
else
[Link]("Not Palindrom");
}

Page 3 of 4
_______ void peli(int no, int original) {
if(no==0) {
if(sum==original)
b = true;
else
b = false;
return;
}
int rem = no%10;
sum = sum*10 + rem;
peli(________ , original);
}
}
Expected Output:
If we enter no : 121, Output will be “Palindrom”
If we enter no : 123, Output will be “Not Palindrom”

Q. III [B] Write JAVA program for the following.


1. Write a JAVA program which will demonstrate the concept of [8]
partial interface and extending interface.
OR
1. Write a JAVA program which will throw customised exception if [8]
entered string length is greater than 6.

Page 4 of 4

You might also like