You are on page 1of 2

United International University

Department of Computer Science and Engineering


CSE 1115: Object Oriented Programming
In Class Assessment 01, Spring 2021 Time: 30 Mins

Any evidence of plagiarism or copy will be punishable according to the proctorial rules of UIU

1. What will be the output of the following program? [1]

public class StringTester {


public static void main(String[] args) {
String a = "Hello";
String b = a;
b = b + " Java";
System.out.println(a);
System.out.println(b);
}
}

2. What will be the output of the following program? [1]

public class ArrayTester {


public static void main(String[] args) {
int [] a = {1,2,3,4,5};
for (int x:a) {
x = 5;
}
for (int x:a) {
System.out.print(x+" ");
}
}
}

3. What will be the output of the following program? [1]

public class Latim {


public boolean a;
public Latim(){
System.out.println(a);
a=true;
}
public static void main(String[] args) {
Latim l = new Latim();
System.out.println(l.a);
}
}

1
4. The following code will not compile. What is wrong with the following program? [1]

public class Tester {


public final int x;
private Tester() {
x = 10;
}

public static void main(String[] args) {


Tester t = new Tester();
t.x=20;
System.out.println(t.x);

}
}

5. Write a program in Java, that will take a student id of UIU as input/parameter to the main program [2]
and prints the department of the student. Note that student id of EEE starts with 012, CSE starts
with 011 and BBA starts with 111.

6. Write a class in Java called ‘Time’. It will have three integer fields. Create a parameterized constructor. [2]
Also write a toString() method so that the output of the main method is as following:

public static void main(String[] args) {


System.out.println(new Time(11,12,12));
System.out.println(new Time(12,12,12));
System.out.println(new Time(13,12,12));
}
output:
11:12:12 AM
12:12:12 PM
1:12:12 PM

7. Write a function in java that will take a String as input. It will return another string where all the [2]
words in the string are separated by ‘*’ instead of spaces.

input: "Shakib Al Hasan"


output: "Shakib*Al*Hasan"

Page 2

You might also like