Sunday 8 November 2015

JAVA MCQS PART 2 FOR UGC NET COMPUTER SCIENCE


                           JAVA MCQS PART 2 FOR UGC NET COMPUTER SCIENCE
      1.       Predict the output:
public class Cdac
{
public static void main(String args[])
{
String s1="sun";
System.out.println(s1.substring(2));
}
}
A.      -1
B.      0
C.      ArrayIndexOutOfBoundsException
D.      StringIndexOutOfBoundsException
Ans.: D

      2.       Which of the following  modifier can be applied to a constructor.
A.      Private
B.      Abstract
C.      public
D.      All of the above
Ans.: c

      3.       Inner classes cannot declare ------------  variables.
A.      Protected
B.      Final
C.      Static
D.      Transient
Ans.: D


      4.       The term instance variables is another name for
A.      Static field
B.      Non static field
C.      Local variable
D.      None of the above
Ans.: B

       5.       Predict the output:
public class Cdac{
public static void main(String [] args){
double value = -9.0;
System.out.println(Math.sqrt(value));
}
}
      A.      3.0
      B.      -3.0
      C.      NaN
      D.      None of the above
Ans.: C


      6.    In Java, Objects are passed by value or reference?
A.  By value
            B.      By reference
            C.      It depends upon how you specify
            D.      Both A and B
Ans.: A


7.       Which collection class allows you to access its elements by associating a key with an element’s value, and provides synchronization?
A. java.util.SortedMap
B. java.util.TreeMap
C. java.util.TreeSet
D. java.util.HashTable
Ans.:D

8. Which one is true about interface and abstract class?
A. Abstract class can have only instance method and default behavior. Interface can declare constants and can have instance method but cannot implements default behavior.
B. An interface has all public members and abstract class has private, protected etc members
C. Both 1 & 2
D. None of the above
Ans.:C

9. Which is valid declaration within an interface?
A. public static short stop = 23;
B. protected short stop = 23
c. transient short stop = 23;
D. final void short stop;
Ans.: A

Click to buy Trueman's UGC NET Computer Sceince Book
10. What is the error in the following code?

class Test
{
abstract void display( );
}
A.  No error
B.  Method display( ) should be declared as static
C.  Test class should be declared as abstract
D.Test class should be declared as public
Ans.:C


11. Which of these is interface in the collection framework.Select the correct answers.
A.  Array
B.  Vector
C.  Linked List
D.  Set
Ans.: D

12. Which of the following is not a keyword?
A.  main
B.  public
C.  static
D.  void
Ans.: A

13. Which keyword can protect a class in a package from accessibility by the classes outside the package?
A.  private
B.  protected
C.  Final
D.  Don`t use any keyword at all
Ans.: D

14. Which variables can an inner class access from the class which encapsulates it?

A.  All static variables,all final variable ,all instance variable.
B.  Only final static variables
C.  Only final instance variables
D.  only public variable
Ans.: A

15. Which of the following are reserved keywords?
a. public
b. static
c. void
d. main
e. String
f. args
A.  a,b,c
B.  a,b,d
c.  a,c,d,e,f
D.  all of these.
Ans.: A

16. ________ Class is Super class for all java exception classes
A.  Throwable
B.  Throw
C.  ThrowsException
D.  all
Ans.:A

17. Java Compiler stores the .class files in the path specified in CLASSPATH environmental variable.
A. True
B.False
C. It depends on situation
D. None of the above
Ans.:B
Note: class file is stored in the location where the java file is available.

18. Java`s garbage collector runs as a ________ priority thread
waiting for ________ priority threads to relinquish the processor.
A.  high ,low
B.  low ,low
C.  high ,high
D.  low ,high
Ans.: D


19. What will be the output?
public class demo
{
public static void main(String args[])
{
for(int i=12;i>0;i-=3)
System.out.println(i);
System.out.println(" ");
}
}

A.  129630
B.  12963
C.  12
D.  none of the above
Ans.: B

20. Constructors can not be inherited or overriden.
A. False
B. True
C. Cant say
D. None of the above

Ans.: B

No comments:

Post a Comment