Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

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

Download as pdf or txt
Download as pdf or txt
You are on page 1of 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