MCQ

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

1) Given:

public abstract interface Interface1


{
public void method(String s);
}
Which of the following is/are correct class implementation(s).

a) public abstract class Class1 implements Interface1


{
public abstract void method(String s) { }
}

b) public abstract class Class1 implements Interface1 { }

c) public class Class1 extends Interface1 {


public void method(Integer i) { }
}

d) public class Class1 implements Interface1 {


public void method(String i) { }
public void method(Integer s) { }
}

Answer: b) and d)

2) Predict the output

import java.util.*;
public class TestMain
{
public static void main(String[] args)
{
String[] str = { “Banana”, “Apple”,”Watermelon”, “Mango” };
sortFruit o = new sortFruit();
Arrays.sort(str, o);
for (String s : str)
System.out.print(s + “ “ );
System.out.println(Arrays.binarySearch(str, “map”));
}

static class sortFruit implements Comparator<String>


{
public int compare(String str1, String str2) {
return str2.compareTo(str1);
}
}
}

a) Watermelon Mango Banana Apple -5


b) Apple Banana Mango Watermelon -4
c) Apple Banana Mango Watermelon -4
d) Apple Banana Mango Watermelon -5

Answer: a)

3) Which of the following program has the lowest run-time complexity?

a) Tower of Hanoi
b) Sum of n Digits
c) Find even or odd
d) Fibonacci series

Answer: d)

4) Which is the correct way of indicating an XML Attribute?

a. <person country="India">
b. <person country=India>
c. <person country;"India">
d. <person country,"India">

Answer: a)
5) Given:

class TestMain {
public static void main(String[] args) {
check();
check(10);
check(10,20);
}
//insert code here
}

Which of the following statement can replace // insert code here, that
will compile without any errors? (Choose all that apply.)

a) static void check(int... checkArgs) { }


b) static void check(int[] checkArgs) { }
c) static void check(int... checkArgs, int y) { }
d) static void check(int checkArgs...) { }
e) static void check(int x, int... checkArgs) { }

Answer: a)

6) Predict the output

class Mammal {
String name = "Dog ";

String makeNoise() {
return "BOW WOW";
}
}

class Cat extends Mammal {


String name = "Cat ";

String makeNoise() {
return "Meow";
}
}

public class TestMain {


public static void main(String[] args) {
new TestMain().go();
}

void go() {
Mammal m = new Cat();
System.out.println(m.name + m.makeNoise());
}
}

a) Cat Meow
b) Dog BOW WOW
c) Dog Meow
d) Cat BOW WOW

Answer: c)

7) Which is not a JQuery method.


a) text()
b) html()
c) val()
d) body()

Answer: d)

8) The following code snippets belongs to ________.

int Search(int arr[], int s, int toFind)


{
int index , retVal = -1;
for( index=0; index &lt s; index++)
{
if ( toFind == arr[index] )
{
retVal = index;
break;
}
}
return retVal;

}
a) Linear Search
b) Binary Search
c) Merge Sort
d) Quick Sort

Answer: a)

9) Predict the output

class TestMain {
static String s = "*";

public static void main(String[] args) {


new TestMain().s1();
System.out.println(s);
}

void s1() {
try {
S2();
} catch (Exception e) {
S += "c";
}
}

void s2() throws Exception {


s3();
s += "2";
s3();
s += "2b";
}

void s3() throws Exception {


throw new Exception();
}
}

a) *c
b) *c22b
c) *c2
d) *c2b
e) *22b

Answer: a)
10) Select the statements that are true about Persistence?

a) Persistence is a way through which the life time of object exists even after the
program terminates
b) Java uses serialization for object persistence
c) Java uses serialization for object persistence
d) Persistence of object is done by java runtime automatically

Answer: a),b)

11) Consider eth following table structure and write a query to display all
the employees who have and don’t have department id assigned
Emp(fname,lname,dno)
Dept(deptid, dname)

a) SELECT FNAME,DEPTID,DNAME FROM EMP E, DEPT D WHERE


E.DNO(+)=D.DEPTID;
b) SELECT FNAME,DEPTID,DNAME FROM EMP E LEFT OUTER JOIN DEPT D
ON (E.DNO= D.DEPTID) ;
c) SELECT FNAME,DEPTID,DNAME FROM EMP E, DEPT D WHERE
E.DNO=D.DEPTID(+);
d) SELECT FNAME,DEPTID,DNAME FROM EMP E FULL OUTER JOIN DEPT D
ON (E.DNO= D.DEPTID) ;

Answer: a),b)

12) Which key can be used to change the mode from input mode to command
mode ?

a. Esc
b. Esc + i
c. Esc + a
d. Esc + l

Answer: a)
13) Carefully read the question and answer accordingly.
Analysis of selection algorithm eliminates ______ number of elements
each time.

a) n elements
b) n/2 elements
c) n/4 elements
d) (n/2)+n elements

Answer: a)

14) Predict the output

class Milon {
Milon() {
}

Milon(Milon m) {
m1 = m;
}

Milon m1;

public static void main(String[] args) {


Milon m2 = new Milon();
Milon m3 = new Milon(m2);
m3.go();
Milon m4 = m3.m1;
m4.go();
Milon m5 = m2.m1;
m5.go();
}

void go() {
System.out.print("hi ");
}
}

a) hi
b) hi hi
c) hi hi hi
d) hi hi followed by Exception
e) hi followed by Exception

Answer: d)
15) Which of the given phases consume more time during the Software life
cycle.

a) Analysis
b) Design
c) Testing
d) Maintenance

Answer: d)

You might also like