0% found this document useful (0 votes)
76 views

B.E. Mid-Semester Examination September 2016: LDRP Institute of Technology & Research, Gandhinagar

This document contains a mid-semester examination for an Object Oriented Programming with Java course. It has 3 questions covering topics like Java output for code snippets, error identification and correction in code, and writing multi-threaded Java programs. Question 1 has 8 code snippets to output. Question 2 has 2 code snippets with errors to identify and correct. Question 3 gives 2 programming problems to write multi-threaded Java code for printing numbers or thread greetings in sequence.

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)
76 views

B.E. Mid-Semester Examination September 2016: LDRP Institute of Technology & Research, Gandhinagar

This document contains a mid-semester examination for an Object Oriented Programming with Java course. It has 3 questions covering topics like Java output for code snippets, error identification and correction in code, and writing multi-threaded Java programs. Question 1 has 8 code snippets to output. Question 2 has 2 code snippets with errors to identify and correct. Question 3 gives 2 programming problems to write multi-threaded Java code for printing numbers or thread greetings in sequence.

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
You are on page 1/ 4

Enroll. No.

/
KADI SARVA VISHWAVIDYALAYA
ID
LDRP INSTITUTE OF TECHNOLOGY & RESEARCH, GANDHINAGAR
B.E. MID-SEMESTER EXAMINATION SEPTEMBER 2016
Date : 02/09/2016 Branch : CE & IT
Subject Name & Code: Object Oriented Programming with JAVA Semester : V
Subject Code: CE 505 / IT 505
Time : 8:30 AM to 10:00 AM Max. Marks : 30
Instructions: 1) All questions are compulsory.
2) Figures to the right indicate full marks.
3) Use of scientific calculator is permitted.
4) Indicate clearly, the options you attempt along with its respective question number.
5) Use the last page of main supplementary for rough work.

Q. I Give output of following code.


If the output of any program is an error according to you, you have to
mention which type of error it is. i.e. Compile time , Runtime
1. class Equals { [2]
public static void main(String [] args) {
int x = 100;
double y = 100.1;
boolean b = (boolean) (x = (int) y) ;
System.out.println(b);
}
}
2. class Test { [2]
public static void main(String [] args){
int x= 0;
int y= 0;
for (int z = 0; z < 5; z++) {
if (( ++x > 2 ) && (++y > 2)) {
x++;
}
}
System.out.println(x + " " + y);
}
}
3. class thread implements Runnable{ [2]
Thread t;
thread(){
t = new Thread(this);
t.start();
t.start();
}
public void run(){
System.out.println("Executed");
}
public static void main(String arg[]){
thread t1 = new thread();
}
}

page 1 of 4
4. class Test { [2]
public static void main(String[] args) {
for(int i = 0; 1; i++)
{
System.out.println("Hello");
break;
}
}
}

5. class ConstructorChaining{ [2]


int a,b ;
ConstructorChaining(){
this(1,2);
System.out.println("Default constructor");
}
ConstructorChaining(int x , int y){
this(1,2,3);
a=x;
b=y;
System.out.println("Two argument constructor");
}
ConstructorChaining(int a , int b, int c){
System.out.println("Three argument constructor");
}

public static void main(String[] args)


{

ConstructorChaining obj=new ConstructorChaining();


System.out.println(obj.a);
System.out.println(obj.b);
}

}
6. class shft [2]
{

public static void leftshift(int i, int j)


{
i <<= j;
}

public static void main(String args[])


{
int i = 4, j = 2;
leftshift(i, j);
System.out.println(i);
}
}

page 2 of 4
7. class rem { [2]
static int s;
public static void main(String [] args) {
rem p = new rem();
p.start();
System.out.println(s);
}
void start(){
int x = 7;
twice(x);
System.out.print(x + " ");
}
void twice(int x) {
x = x*2;
s = x;
}
}
8. [2]
class A{
static int i = 1111;
static{
i = i-- - --i; }
{
i = i++ + ++i;
}
}
class B extends A{
static{
i = --i - i--; }
{
i = ++i + i++;
}
}
class MainClass {
public static void main(String[] args) {
B b = new B();
System.out.println(b.i);

}
}

Q. II Find out error(s) if any in the following code and correct it and give
the output.
1. abstract class view{ [3]
protected void view(){
System.out.println("Constructor");
}
private void test(){
System.out.println("test Method");
}
private abstract void demo();

page 3 of 4
class dummy extends view{
dummy(){
System.out.println("Dummy Method");
super();
}
public static void main(String arg[]){
dummy d = new dummy();
d.demo();
}
private void demo(){
System.out.println("Demo Method");
}
}

2. class MainClass{ [3]


public static void main(String[] args) {
int i = 10 + + 11 - - 12 + + 13 - - 14 + + 15;
System.out.println(i);
// \u000d System.out.println("Calculation");
System.out.print("ONE"+1+2+"TWO"+"THREE"+3+4+"FOUR"+5);
}
}
Q. III Write java program for the following.
1. WAP to create two threads namely Even and Odd on same object. One [8]
thread will print only even number while another one will print odd
numbers. You should structure your program such that output must be in
proper sequence.
Odd 1
Even 2
Odd 3
Even 4 …
OR
1. WAP to create a thread (let's call it Thread 1). Thread 1 creates another [8]
thread (Thread 2); Thread 2 creates Thread 3. Each thread should print
"Hello from Thread <number>!", but you should structure your program
such that the threads print their greetings in reverse order.

page 4 of 4

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy