Kadi Sarva Vishwavidhyalaya: LDRP Institute of Technology and Research

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

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. System.out.println(10.10%20); [1]
2. System.out.println("\u0042"); [1]
3. double d = 323.142; [1]
byte b;
b = (byte) d;
System.out.println(“b = “ + b);
4. class gp { [3]
int a;
gp() { System.out.println(“GP-Default”); }
gp(int x) { System.out.println(“GP-Parameterised”); }
}
class parent extends gp {
parent() { System.out.println(“Parent-Default”); }
parent(int x) { System.out.println(“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++;
System.out.println(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;
System.out.println(a);
}
System.out.println(a);
}
2. interface int1 { [3]
int a;
void put();
}
class myClass implements int1 {
void put() {
System.out.println(“Method Called”);
}
class DemoPaper {
public static void main(String ar[]) {
int1 c1 = new int1();
c1.put();
}
}
3. class gp { [2]
gp() {
System.out.println("Default - GP");
}
gp(int x) {
System.out.println("Parameterised - GP");
}
}
class p extends gp {
p() {
System.out.println("Default - P");
}
p(int x) {
System.out.println("Parameterised - P");
}
}
class child extends p {
child() {

Page 2 of 4
super(10);
System.out.println("Default - child");
}
child(int x) {
System.out.println("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 = Integer.parseInt(args[0]);
_________ . fibo(__ ,__ ,no);
}
_______ void fibo(int f1, int f2, int no) {
int f3;
if(no==0) {
return;
}
f3 = f1 + f2;
System.out._________(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 = Integer.parseInt(args[0]);
_____________ . peli(no,________);
if(_____)
System.out.println("Palindrom");
else
System.out.println("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