Java - Online Test - Cognizant (cts) - javasearch.buggybread.com


Share

Search Java Test Questions


 223 test questions in repository.




Java - Test Questions on 'Cognizant (cts)' - 26 questions found


Which of the following is true ?Core Java
We can serialize static variables
We can serialize transient variables
We can serialize final variables
We can serialize instance methods

  serialization  java  file io

What is the initial state of a thread when it is created and started ?Core Java
Wait
Running
Ready
Sleep

  java  threads  multithreading  thread states

What state does a thread enter when it terminates its processing?Core Java
Wait
Ready
Dead
Running

  java  threads  multithreading  thread states

How can we execute a Java class independently if it doesn't have a static main method ?Core Java
By initiating the flow in any of the static method
By initiating the flow in any of static block
By initiating the flow in any other instance method named as main
By initiating the flow in any other instance method named as main and making it final

  main method  java

Which keyword is used to provide explicit access of a code block to single thread ?Core Java
Transient
Final
Explicit
Synchronized

  java  threads  multithreading

Which of the following is not possible ?Core Java
try block followed by catch
try block followed by finally
try block followed by catch block and then finally
try block without catch or finally block

  exceptions  java  try-catch  finally

Which of the following is false about main method ?Core Java
It should be declared public and static
it should have only 1 argument of type String array
We can override main method
We can overload main method

  java  main method

Which of the following class creates mutable objects ?Core Java
Boolean
File
String
StringBuffer

  java  immutable

Which of the following is wrong for final instance variables ?Core Java
They cannot be changed after initialization
They can be initialized directly within static method
They can be declared and initialized together at the same place
They can be initialized within constructor

  java  final  final variable  java keywords

Which of the following is false for final ?Core Java
Final methods cannot be overriden
Final methods cannot be overloaded
Final classes cannot be subclassed
Final class cannot be abstract

  java  final  java keyword

Which of the following has been introduced with Java 8 ?Core Java
StringBuffer
StringBuilder
StringFilter
StringJoiner

  java  java8  java 8  String  StringJoiner

When String literals are compared using ==, they always returns true if the string values are same because .. Core Java
of overridden compareTo method
of overridden compare method
of String Pool
== means that the object contents are equal

  

In case of String Literals ..Core Java
x==y on all literals always returns false
x.equals(y) on all literals always returns false
if x.equals(y) returns true, x==y returns true too
if x.equals(y) returns false, x==y returns true

  

What will be the output of following code ?

String str1 = "String1";
String str2 = "String2";
str1.concat("String3");
System.out.print(str1);
System.out.print(str2);
Core Java
String1String2
String1String3String3
String1String3String1String3
String1String1

  

Which of the following is false ?Core Java
A Class cannot override both hashcode and equals method.
A class can override both hashcode and equals method.
A Class must override hashCode method if its overridding equal method.
A Class can override hashCode even if its not overridding equals method.

  hascode  equals method  overridding hashcode and equals method

What will be the output of exceuting main method ?

public static void main(String[] args){
      List list = new ArrayList();
      list.add(1);
      list.add(2);
      list.add(3);
      System.out.println(list);
   }
Core Java
1,2,3
Order cannot be determined
compilation error
3,2,1

  collections  list  arraylist

What will be the output upon executing main method ?

public static void main(String[] args){
      Set set = new HashSet();
      set.add(1);
      set.add(2);
      set.add(3);
      System.out.println(set);
   }
Core Java
1,2,3
Order cannot be determined
Compilation error
3,2,1

  set  hashset  collections

Which of the following class creates immutable objects ?Core Java
String
StringBuffer
StringBuilder
None of these create immutable objects.

  String  StringBuffer  StringBuilder  Immutable

Which of the following class is synchronized ?Core Java
String
StringBuffer
StringBuilder
None of these

  String  StringBuffer  StringBuilder  Synchronized

Binary Search requires that the collection should beAlgorithm
Sorted in Ascending Order
Sorted in Descending Order
Sorted in any Order
Unsorted

  Binary Search  Search  Algorithm

Which of the following methods are used by Java Garbage Collection Mechanism ?Core Java
final
finally
finalize
All of the above

  garbage collection  finalize

Which of the following can be overridden ?Core Java
final instance methods
final static methods
non final instance methods
non final static methods

  overriding

Which of following are serialized ?Core Java
static variables
transient variables
instance variables
method local variables

  serialization

In which case finally won't get executed ?Core Java
in case of exception
in case of normal execution
in case of return statement before end of try block
in case of force program termination

  finally

Which of the following file is called deployment descriptor ?Java EE
application.xml
web.xml
config.xml
web-application.xml

  deployment descriptor

In Case a method is declared to throw an exception , We can only use a call to that method if ...Core Java
We use the call within try block and catch the exception
We declare that the method is expected to throw the exception using throws
Both 1 and 2
Either 1 or 2

  exception handling  throws







comments powered by Disqus