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

Java BS Mid Paper 2014

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

The University of Lahore

CS & IT Department
CS-4110 JAVA Software Development Paradigm
Mid Examination: Date: 11/04/2014
Course Dr. Muhammad Atif Computer allowed No
Instructor Ms. Iram Noreen
Exam Type Closed Book Calculator allowed No
Time Allowed 90 minutes Max. Marks 60

Name: ------------------------------------------------ Section: -------------------

Reg #: ----------------------------------- Semester: ---------------------

General Instructions
1. Please make sure your mobile is OUTSIDE the examination hall.
2. You have to answer all the questions until advised otherwise. Use fountain pen or ball
point to answer the questions.
3. Over writing and cutting is not allowed in sections.
4. You can ask for additional sheets for the descriptive part of the paper.
5. While answering descriptive questions please be precise and to-the-point.
6. All the queries about this paper must be asked in first 30 minutes. No query shall be
entertained after this time. If you don’t understand anything use your best guess and
answer the question.
7. Any use of unfair means (copying, cheating, exchanging any items etc) during the paper
shall DISQUALIFY you from this exam immediately, NO EXCEPTIONS.
8. Absolutely NO TALKING or WHISPRING during the exam.
9. Attach your admit slip, Question paper and answer sheet in top to bottom order.

Java MidTerm Exam, Friday, 11 April 2014


Page 1
A) Select the best output option. (20 marks)
1.  Which of the following are valid array declarations? (2)

A. int arr[] = new int[];


B. int arr[][] = new int [10][10];
C. float arr[][] = new float[][10];
D. float arr[] = new float[10];

2. What will be the output of the following program? (2)

public class Test3 {


public static void main(String[] args) {
System.out.println("Main Method1");
}
public static void main(String args){
System.out.println("Main Method2");
}
}
Choose the one below:
A. Main Method1
B. Main Method1 Main Method2
C. Main Method2
D. Runtime Exception
E. Compile time error

3. What will be the output of the following program? (2)


1. public class Test1{
2. public static void main(String[] args){
3. int []arr ={1,3,5,7,9};
4. for(int i = 0;i < arr.length;i++){
5. System.out.println(arr[i++]);
6. }
7. }
8. }
Choose the one below:
A. Error at line 3 as array notation is not proper it should be int arr[]={1,3,5,7,9};
B. ArrayIndexoutOfBoundsException
C. Output is: 1 5 9

Java MidTerm Exam, Friday, 11 April 2014


Page 2
D. Output is: 3 7

4. What will be the output? (2)


public class Test3{
public void method(){
System.out.println("Called");
}
public static void main(String[] args){
method();
}
}
Choose the one below:
A. “Called”
B. Compiler will report an error
C. The above program will be compiled but there is a runtime error.
D. Nothing

5. What will be the output? (2)


public class A {
public A() {
System.out.println("A");
}
Void arslan (){
System.out.println("Arslan");

}
}
public class B extends A {
public B() {
System.out.println("B");
}
Void arslan (){
System.out.println("TAlha");

}
public class Test {

Java MidTerm Exam, Friday, 11 April 2014


Page 3
public static void main(String... args) throws Exception {
B b = new A();
}
}
Choose the one below:
A. A B A
B. A B A B
C. B B
D. A B

Java MidTerm Exam, Friday, 11 April 2014


Page 4
6. Select the correct syntax for main method : (2)
A. public void main(String args[])
B. public static void main(String args)
C. public static void Main(String args[])
D. None of the Above

7. Consider the following few lines of code, determine its output.  (2)
String s1 = new String(“hi”);
String s2 = "hi";
System.out.println(s1 ==s2);
System.out.println(s1.equals(s2));

A. false true
B. true false
C. true true
D. None of the above.

8. What will be the output? (2)


public class Test9{
static int k = 1;
{
k = k * 2;
}
public static void main(String args[]){
System.out.println(k);
}
}

Choose the one below:


A. 1
B. 2
C. 4
D. Compiler Error

9. What will be the output? (2)

public class Candy{


private String flavor;

Java MidTerm Exam, Friday, 11 April 2014


Page 5
Candy(String val){
flavor = val;
}
private int test () {
System.out.println(“this is a test for Candy”);
return 1;
}
private static void eat(){
System.out.println(“you are easting this Candy”);
}
public static void main (String[ ] args){
System.out.println (test ());
}
}

A. this is a test for Candy


B. Non-static method test () cannot be referenced from a static context.
C. Invalid return type of test()

10. What will be the output? (2)

public final class Car {

private int Model;


private double price;

void run () { /* some code */ }


void start(){ /* some code */ }
void stop(){ /* some code */ }

public class Suzuki extends Car public class Mercedes extends


{ Car{
/* some code */ /* some code */
} }

A. Run time error


B. Compile time error
C. Code will compile and run successfully.

Java MidTerm Exam, Friday, 11 April 2014


Page 6
B) Find the output if the following programs are correct or otherwise rewrite it
after making corrections (15 marks)

11. (5 marks)
public class Test6{
public Test6(){
super(4);
}
public Test6(int var){
System.out.println(var);
}
public static void main(String[] args){
Test6 t6 = new Test6();
}
}

12. (5 marks)

public class Test7{


public Test7(){}
public Test7(Test7 ref){
this (ref,"Hai");
}
public Test7(Test7 ref,String str){
ref.Test7(str);
System.out.println("Hi");
}
public void Test7(String str){
System.out.println(str);
}
public static void main(String[] args){
Test7 t = new Test7();
Test7 t7 = new Test7(t);
}
}

13. (5 marks)

public class Test5{


Java MidTerm Exam, Friday, 11 April 2014
Page 7
public static void main(String args[]){

System.out.println(I.k);

class I{

int k=100;

C) Select best option from available choices. (10 marks)


14. Which variable is shared by all instances of class?

A. field variable B. final variable C. instance variable D. static variable

15. ________________ package is by default loaded internally by the JVM.

A. java.io B. java.AWT C. java.lang D. java.Collection

16. Which one is non-primitive type?

A. int B. float C. char D.


String

17. A try block can have _________ catch blocks.

A. 1 B. 2 C. 3 D. many

18. Which one is a valid declaration of a boolean?


a) boolean b1 = 0; b) boolean b2 = 'false';
c) boolean b3 = false; d) boolean b5 = no;

19. Which one manages Local variables and methods in JVM.


A. Queue B. Stack C. Heap D. A & B

20. System.out.println(“Lahore”.substring(2, 4)) will print ________?

A. hor B. ore C. ho D. none of these

Java MidTerm Exam, Friday, 11 April 2014


Page 8
D) Write a program that takes arbitrary number of values as command line arguments.
Suppose a user inputs only integers values. Write a program to get the average of those
values which are even.  (5 marks)

Java MidTerm Exam, Friday, 11 April 2014


Page 9
Part A : / 20 Part B : / 15
(2 marks each) (5 marks each)

1.        11.   

2.        12.   

3.        13.   
Part C : / 6
4.        (1 mark each)

5.        14.   

6.        15.   

7.        16.   

8.        17.   

9.        18.   

10.    19.   

20.   
Part D: / 10

Total Marks : 50 Obtained Marks:

Answer Table: (Use capital letters to answer the correct option of MCQs.)

Java MidTerm Exam, Friday, 11 April 2014


Page 10
Java MidTerm Exam, Friday, 11 April 2014
Page 11

You might also like