java questions for practice




1. Iterator returned by Hashtable on key, value and entry are?

A. Fail-fast

B. Fail-safe

C. None of the above 

2.Which of these are selection statements in Java ?

A. break

B. continue

C. for()

D. if()

3.Which of these is a legal definition of a method named examveda assuming it throws IOException, and returns void. Also assume that the method does not take any arguments. Select the one correct answer.

A. void examveda(void) throws IOException{}

B. void examveda() throw IOException{}

C. void examveda() throws IOException{}

D. void examveda() {} throws IOException

4.Which of these statement is incorrect ?

A. The main() method must be made public.

B. There can be only one main() method in a program.

C. Applets do not require a main() method at all.

D. Every class must contain a main() method.

5.Iterator returned by ConcurrentHashMap on key, value and entry is?

 A. Fail-fast

 B. Fail-safe

 C. None of above

6.Which of the following statements is correct ?

A. Public method can be accessed by calling object of the public class.

B. Public method can only be called by object of its class.

C. Public method is accessible only to subclasses of its parent class

D. Public method is accessible to all other classes in the hierarchy

7.Iterator returned by LinkedHashMap on key, value and entry is?

A. Fail-fast

B. Fail-safe

C.  None of the above

8.hat is the return type of a method that does not returns any value ?

A. double

B. void

C. float

D. int

9.What is the process of defining more than one method in a class differentiated by method signature ?

A. Function doubling

B. Function overloading

C. Function overriding

D. None of the above

10.Which of the following is a method having same name as that of its class ?

A. constructor

B. class

C. delete

D. finalize

11.Which method can be defined only once in a program ?

A. private method

B. static method

C. finalize method

D. main method

12.Iterator returned by TreeMap on key, value and entry is?

A. Fail-fast

B.  Fail-safe

C. None of the above

13. Which of these statement is incorrect ?

A. main() method must be made public.

B. All object of a class are allotted memory for the all the variables defined in the class.

C. If a function is defined public it can be accessed by object of other class by inheritation.

D. All object of a class are allotted memory for the methods defined in the class.

14.What is the return type of Constructors ?

A. void

B. int

C. float

D. None of the above

15.Iterator returned by ConcurrentSkipListMap on key, value and entry is?

A.  Fail-fast

B. Fail-safe

C. None of the above

16. Which keyword is used by method to refer to the object that invoked it ?

A. this

B. abstract

C. catch

D. import

17.Which of the following statements are incorrect ?

A. finalize() method must be declared protected.

B. Default constructor is called at the time of declaration of the object if a constructor has not been defined.

C. Constructor can be parameterized.

D. finalize() method is called when a object goes out of scope and is no longer needed.

18.What is process of defining two or more methods within same class that have same name but different parameters declaration ?

A. method hiding

B. method overloading

C. method overriding

D. None of the above

19.Which of these keyword can be used in subclass to call the constructor of superclass ?

A. extends

B. extent

C. this

D. super

20.What is the process of defining a method in subclass having same name & type signature as a method in its superclass ?

A. Method hiding

B. Method overloading

C. method overriding

D. None of the above

21.Which of these keywords can be used to prevent Method overriding ?

A. final

B. protected

C. constant

D. static

22.Which Set implementation is sorted and synchronized?

 A. LinkedHashSet

 B. ConcurrentSkipListSet

 C. TreeSet

 D. CopyOnWriteArraySet

23.Which of these is correct way of calling a constructor having no parameters, of superclass A by subclass B ?

A. super();

B. super.A();

C. superclass.();

D. super(void);

24.TreeMap –

A. Doesn't enable null key

B. Allow several null values

C. Both the above

25. Which of these is supported by method overriding in Java ?

A.  Polymorphism

B. Encapsulation

C. Abstraction

D. None of the above

26.Which of these is correct about passing an argument by call-by-value process ?

A. Reference to original argument is passed to formal parameter of the subroutine and changes made on parameters of subroutine have effect on original argument.

B. Copy of argument is made into the formal parameter of the subroutine and changes made on parameters of subroutine have effect on original argument.

C. Reference to original argument is passed to formal parameter of the subroutine.

D. Copy of argument is made into the formal parameter of the subroutine.

27.What is the process of defining a method in terms of itself, that is a method that calls itself ?

A. Recursion

B. Encapsulation

C. Abstraction

D. Polymorphism

28.What will be the output of the following code –

import java.util.Collections;

import java.util.HashMap;

import java.util.Map;


public class MyClass

{

public static void main(String args[])

{

Map<Integer,String> hashMap = new HashMap<Integer,String>();

hashMap.put(11,”a”);

Collections.unmodifiableMap(hashMap);

hashMap.put(12,”b”);

System.out.println(hashMap);

}

}

 A. {11=a}

 B. {11=a, 12=b}

 C. UnsupportedOperationException

 D. Compile time exception

29.Which of them is a not command line Tool?

A .java

B.javaw

C.javapath

D.javadoc

30.What will be the output of the following code –

import java. util.Hashtable;

import java. util.Map;

public class hashTableBlog {

public static void main (String args[])

{

Map<Integer,String> hashtable = new Hashtable<Integer,String>();

hashtable.put(11,”a”);

hashtable.put(null,”c”);

hashtable.put(null,null);


System.out.println(hashtable.size());

System.out.println(hashtable);

}

}


A. Runtime Exception

B. Compile time exception

C. 2 {11=bmw, null=fer}

31.What will be the output of the following code –

import java. util.HashMap;


class newEmployee

{

private String name;

public newEmployee (String name)

{

this.name = name;

}

@Override

public int hashCode()

{

return 1;

}

}


class EmployeeClass

{

public static void main(String args[])

{

HashMap hm=new HashMap();

hm.put(new newEmployee(“a”),”emp1″);

hm.put(new newEmployee(“b”),”emp2″);

hm.put(new newEmployee(“a”),”emp1 overridden”);


System.out.println(hm.size());

System.out.println(hm.get(new newEmployee(“a”)));

}


}


 A. 1 null

 B. 2 emp1 OVERRIDDEN

 C. 3 null

 D. 1 emp1 OVERRIDDEN

32.A/An___instance variable is shared by all instances of the class.It exist even before the object is created

A.instance

B.abstract

C.interface

D.static

33.In Iterator, hasMoreElements() method of Enumeration has been changed to:

A. hasNextElement()

B. isNext()

C. hasNext()

D. name remains same

34.Which of the following is not a method of java.util.ArrayList?

A.add(Object x)

B.remove(Object x)

C.contains(Object x)

D.insert(int i,Object x)

E.set(int I,Object x)

35.TreeSet internally uses that one to store elements?

A.  HashMap

B. LinkedHashMap

C. TreeMap

36.Providing access to the object only through its member functions,while keeping the details private is called_____

A.information hiding

B.encapsulation

C.Inheritance

D.modularity

37.HashSet internally uses?

A. HashMap

B. LinkedHashMap

C. TreeMap

38.Which of the following best descibes the set of all paires of values for boolean variables a and b such that, (!a && b)==!(a||b) evaluates to true?

A.Empty set

B.one pair a==true,b==false

C.two pairs in which a==true

D.two paires in which a!=b

E.All 4possible combination

39.An attempt to add the null key to a TreeSet will result in:

A. Will compile

B. Compile time Exception

C. Error

D. Runtime – NullPointerException

40.A "has a" relationship between classes represents ___ and "is a" represents__

A.static,nonstatic class

B.Inheritance,Composition

C.Composition,Inheritance

D.Overriding,Overloading

41.TreeSet maintains which order?

A. Ascending Order

B. Descending Order

C. None of the above

42.What is the default layout manager for a panel?

A.BorderLayout

B.Ther is no layout

C.FlowLayout

D.GridLayout

43.Enumeration returned by ArrayList is

A. Fail-fast

B. Fail-safe

C. None of the above

44.What happens in a method if an unchecked exception is thrown in a try block and there is no matching catch block?

A.program ignores exceptn

B.program halts immediately

C.Program will not compile

D.None of the above

45.Which are the values in arr after execution of following.. Int[]arr={1,1,0,0,0}; for(int i=2;i < arr.length;i++) arr[i]=arr[i-1]+arr[i-2];

A.11011

B.1121

C.11222

D.11235

E.11248

46.LinkedHashMap permits

A. One null key

B. Many null values

C. Both the above

47.Which is not a characteristics of Java programming language?

A.Robust

B.Procedural

C.Distributed

D.Multithreaded

48.Hashtable permits

A. One null key

B. Many null values

C. None of the above

49.Which of the following is not a method of the Thread class.

A. public void run()

B. public void start()

C. public void exit()

D. public final int getPriority()

50.A lower precision can be assigned to a higher precision value in Java. For example a byte type data can be assigned to int type.

A. True

B.False


Question No Answer 

1

2

3 C

4

5 B

6

7 A

8 B

9 B

10 A

11

12 A

13

14

15 B

16 A

17

18 B

19

20 C

21 A

22 B

23 A

24 B

25 A

26

27 A

28 B

29 C

30 A

31 C

32 A

33 C

34

35 C

36 B

37 A

38 C

39

40 C

41 A

42 A

43 A

44 B

45

46 C

47 B

48 C

49 C



// Online C compiler to run C program online

#include <stdio.h>

int s[10];

int top=-1;

void push(int data ) {

    s[++top]=data; 

}

void pop(){

    res= s[top]; 

    top--; 

}

void eval(char op, int op1, int op2){

    switch(op){

        case '+':

        return op1+op2;

        case '-':

        return op1-op2;

        case '*':

        return op1*op2;

        case '/':

        return op1/op2;

        

    }

}

int main() {

    // Write C code here

   char a[20]={'2', '3', '+', '4', '-'};

   for(int i=0;i<a[i]!='\0';i++){

      ch= a[i];

      if(ch>'0'&& ch>='9') {

         push('0')!

      }

   }


    return 0;

}



50 A

Post a Comment

Previous Post Next Post