Technical aptitude test 2 CSE

Preview:

Citation preview

Technical Aptitude Test

Date : 18-03-2016

Q.1. Choose one that apply: class S{public static void main(String agr[]){short s1=4; //LINE 1short s2 = s1+=s1; //LINE 2short s3= s1+s2; //LINE 3 byte b1=(byte)s1 +(byte)s2; //LINE 4byte b2=(byte)((byte)s1 +(byte)(byte)s2); //LINE 5 }} A. Comiler Error at Line 1,2,3 B. Compiler Error at Line 3,4.C. Compiler Error at 2,3,5 D. Comiler Error at 1,4,5

Q.2 Classes that can be used to instantiate objects are called concrete classes.A.TRUE B.FALSE

Q. 3. char ** array [12][12][12]; Consider array, defined above. Which one of the following definitions and initializations of p is valid? A) char ** (* p) [12][12] = array; B) char ***** p = array; C) char * (* p) [12][12][12] = array; D) const char ** p [12][12][12] = array; E) char (** p) [12][12] = array;

Q.4 What is the result of following java code?public class Apti {

static void test(int[] a) {int[] b = new int[2];a = b;System.out.print(b.length);System.out.print(a.length); }public static void main(String[] args) {int[] a = new int[5];test(a);System.out.print(a.length);

} }A.225 B.255 C.200 D.222

Q.5 what is the o/p?main(){

printf(“%%%%%”); }

A.%%%%%B.%%%%C.%%%D.%%

Q.6 . #include<iostream>using namespace std;int x = 1;void fun(){ int x = 2; { int x = 3; cout << ::x << endl; }}int main(){ fun(); return 0;}A.1 B.2 C.3 D.0

Q.7 What will be the result of compiling and running the following program ?public class ExceptionTest{public static void main(String[] args) throws Exception{try{m2();}finally{ m3(); }catch ( NewException e ){}}public static void m2() throws NewException { throw new NewException(); }public static void m3() throws AnotherException{ throw new AnotherException(); }

A. It will compile but will throw AnotherException when run.B. It will compile but will throw NewException when run.C. It will compile and run without throwing any exceptions.D. It will not compile.

Q. 8 main(){extern int i;i=20;printf("%d",i); }

Output is:(A)0(B)20(C)would vary from compiler to compiler(D)Error : Undefined symbol i

Q.9 Which type of casting can be used only with pointers and references to objects?A) Dynamic_cast B) cast C)Static_cast D) Pointer_Cast

Q.10 class Student extends String{} What happens when we try to compile this class?A) Will not compile because class body is not definedB) Will not compile because the class in not declared public.C) Will not compile because String is abstract.D) Will not compile because String is final.

Q. 11 What will be output when you will execute following c code?#include<stdio.h>void main(){

int a=5,b=10;if(a<++a||b<++b)printf("C rocks, everyone shocks");elseprintf("%d %d",a,b);

}(A)6 11 (B)6 10 (C)C rocks, everyone shocks (D)none of above

Q.12 What will the following code print?int[] scores1 = { 1, 2, 3, 4, 5, 6};int[] scores2 = { 0, 0, 0, 0, 0, 0};System.arraycopy(scores2, 2, scores1, 3, 2);for(int i : scores2) System.out.print(i);

A. 123006B. 000000C. 000450D. It throw an exception at run time.

Q.13. int main() {

int number1 = 88, number2 = 22; int & refNumber1 = number1; refNumber1 = 11; cout << refNumber1 << endl; refNumber1 = number2; number2++; cout << refNumber1 << endl; cout << number1 << endl; cout << number2 << endl;} O/p:-A.88 23 23 23 B.11 22 22 23 C.11 22 23 23D.11 23 23 23 E.88 22 22 23

Q.14 What will be output when you will execute following c code?#include<stdio.h>void main(){

int a=5; a=a>=4;switch(2){case 0:int a=8;case 1:int a=10;case 2:++a;case 3:printf("%d",a);}

}(A) 2 (B) 10 (C) Compilation error (D)no

output

Q.15 Which of the following should be used 'if content is not fixed and keep on changing(mutable) but Thread safety is required'?A. String B. StringBuffer C. StringBuilder D. Both B & C

Q.16 #include<stdio.h>void main(){

int a=3,b=2;a=a = = b = = 0;switch(a){case 1:a=a+10;}sizeof(a++);printf("%d",a);

}(A)11 (B)12 (C)1 (D)0Associativity : left to right

Q.17 Which of the following concepts means waiting until runtime to determine which function to call?A. Data hiding B. Dynamic casting C. Dynamic binding D. Dynamic loading

Q.18 Which of the following are true about the "default" constructor?Choose 2 options:A. It is provided by the compiler only if the class does not define any constructor.B. It initializes the instance members of the class.C. It calls the default 'no-args' constructor of the super class.D. It initializes instance as well as class fields of the class.E. It is provided by the compiler if the class does not define a 'no- args' constructor.

Q.19 What will be output when you will execute following c code?#define PRINT printf("Star Wars");printf(" Psycho");#include<stdio.h>void main(){int x=1;if(x--)PRINTelseprintf("The Shawshank Redemption");} Choose all that apply:(A) Stars Wars Psycho (B) The Shawshank Redemption(C) Warning: Condition is always true(D) Compilation error

Q.20 Why reference is not same as a pointer?A. A reference can never be null. B. A reference once established cannot be changed. C. Reference doesn't need an explicit dereferencing mechanism. D. All of the above.

Q.21 Which of the following sorting algorithms can be used to sort a random linked list with minimum time complexity?A.Insertion Sort B.Quick Sort C.Heap Sort D.Merge Sort

Explanation: Both Merge sort and Insertion sort can be used for linked lists. The slow random-access performance of a linked list makes other algorithms (such as quicksort) perform poorly, and others (such as heapsort) completely impossible. Since worst case time complexity of Merge Sort is O(nLogn) and Insertion sort is O(n^2), merge sort is preferred.

Q.22. A circularly linked list is used to represent a Queue. A single variable p is used to access the Queue. To which node should p point such that both the operations enQueue and deQueue can be performed in constant time?A. rear node B. Front node C. not possible with single pointer D. node next to front

Q.23 A function f defined on stacks of integers satisfies the following properties. f( ) = 0 and f (push (S, i)) = max (f(S), 0) ∅+ i for all stacks S and integers i.If a stack S contains the integers 2, -3, 2, -1, 2 in order from bottom to top, what is f(S)?A.6 B.4 C.3 D.2

Q.24. In a complete k-ary tree, every internal node has exactly k children or no child. The number of leaves in such a tree with n internal nodes is:A.nk B.(n-1)k+1 C. n(k-1)+1 D.n(k-1)

Q.25. How many distinct binary search trees can be created out of 4 distinct keys?A.4 B.14 C.24 D.42

The base case is t(0) = 1 and t(1) = 1

Q.26. What is time complexity of fun()?int fun(int n){ int count = 0; for (int i = n; i > 0; i /= 2) for (int j = 0; j < i; j++) count += 1; return count;}A O(n^2) B.O(nLogn) C.O(n) D. O(nLognLogn)

Q.27. class Test {

int p = 20; public static void main(String args[]){ final Test t = new Test(); t.p = 30; System.out.println(t.p);

} }A.20 B.30 C. Compile time error D. Runtime error

Q.28. What will be the result of attempting to compile and run the following program?public class TestClass{public static void main(String args[ ] ){String s = "hello";StringBuilder sb = new StringBuilder( "hello" );sb.reverse();s.reverse();if( s == sb.toString() ) System.out.println( "Equal" );else System.out.println( "Not Equal" );}}A. Compilation error. B. It will print 'Equal'.C. It will print 'Not Equal'. D. Runtime error.

No reverese method in String.

Q.29. Which of the following statements are true?

A. For any non-null reference o1, the expression (o1 instanceof o1) will always yield true.B. For any non-null reference o1, the expression (o1 instanceof Object) will always yield true.C. For any non-null reference o1, the expression (o1 instanceof o1) will always yield false.D. For any non-null reference o1, the expression (o1 instanceof Object) may yield false.

Q.30 import java.util.*;public class Test {

public static void main(String[] args) {TreeSet s = new TreeSet();s.add(1);s.add(99.9);s.add(99.9);s.add(96.9);for (int i = 0; i < s.size(); i++) {

System.out.print(s.pollFirst()+" ");} }}

A. 1 96.9 99.9 B.1 96.9 99.9 99.9 C.1 D.compilation errorE.an exception is thrown at run time