MST 2017 PDF

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

Roll Number:

Thapar University Patiala


Computer Science & Engineering Department
BE/ B. Tech.-First Year (II Semester) UTA 009: Computer Programming II
MST : March 21, 2017, 13:00 — 15:00 Hrs
Time: 02 Hours Max Marks: 25
Coordinators: Rajesh Kumar, Singara Singh . . .
new quests
must be started from new page.

Question I

A Discuss the syntax of various loop structures in Java. 3

B Write the output of following program: I

class overload {
int x, y;
void add(int a){ x = a + 1; } •
void add(int a , int b){ x = a + 2; }
} .
class Overload_methods {
public static void main(String args[ ])
{ overload obj = new overload();
int a = 0; '
• obj.add(6);
obj.add(6, 7);
System.out.println(obj.x); }
}
C Define a class Student having two integer instance variables: m1 and m2. Write a method 3
meth(int a, int b) to display the sum of the marks ml and m2. Extend this class to define
another class StudentE having meth(int a, int b) to find the product of the ml and m2.
Initialize the marks ml and m2 using the constructor of StudentE. Show the execution of
the rilethods of both classes using dynamic method dispatch.

Question II
1
A Explain the following Java keywords 2.5

(i) throw (ii) this (iii) final (iv) break (v) continue

B Write a Java program to print the following pattern 4


1
2 3
. 3 • - 4 5 -
5 7
4 6
5:1; 7 8 9
t..
Question III

A Explain signed and unsigned right shift operators with suitable example.
,

P.7.0.
B In a Java program, we have a statement byte x = -15; give the sequence of bits used by the 1.5
system to store x.

C Discuss the output of following program: - 2


class C [
public int x = 1;
public C(int i) { x += i; }
}
class D extends C {
public D(int i) { super(i); x += i; }
}
class E {
public static void main(String argv[]) {
C ar[ ] = new C[2];
ar[0] = new C(1);
ar[1] = new D(2); .
System.out.println(ar[0].x + ar[1].x);
}}
Question IV

A Discuss the output of.following program 1


class MST{

public static void main ( String args[]) {


try ,
{
int x = 0; int y = 5 / x;
System.out.println("Hello"); '
}catch (Exception e) { .
System.out.println("In catch Block");
}
System.out.println("finished");
}}
B Write a program in Java to display the prime numbers in the range of [x, y], x < y, where x' 4
and y are positive integers entered at run time.

C Write the output of following program: 1


interface A{
void method();
}
class One{
public void method(){ - • .
System.out.println("Class One method");
}
}
class Two extends One implements A{
public void method(){
System.out.println("Class Two method");
}
}
public class Test extends Two{
public static void main(String[] args){
A obj = new Two();
. obj.method(); .
}}

You might also like