0

Basics of Java

Description: Simple test to check your java
Number of Questions: 15
Created by:
Tags: java Conditional Statement
Attempted 0/15 Correct 0 Score 0

Which type(s) of linked list is/are used in Java utility package?

  1. Singly linked list

  2. Doubly linked list

  3. Circular linked list

  4. All of the above

  5. None of the above


Correct Option: C
Explanation:

Circular linked list is efficient as compared to others because it has same time complexity for insertion at the first, middle and end.

Which of the following statements is wrong?

class superclass

{

}

class subclass extends superclass

{

}

 

  1. superclass superclassref=new superclass();

  2. superclass superclassref=new sublass();

  3. subclass subclassref=new subclass();

  4. subclass subclassref=new superclass();

  5. Any class reference variable cannot reference other class object.


Correct Option: D
Explanation:

It is not possible to reference a super class object with the sub class reference variable.

What happens in the heap memory when a subclass object is created?

  1. Only for the subclass object, memory will be created.

  2. Only for the superclass object, memory will be created.

  3. Memory for both superclass and subclass will be created and also that memory is referenced by super class reference variable.

  4. Memory for both superclass and subclass will be created and also that memory is referenced by subclass reference variable.

  5. None of the above


Correct Option: D
Explanation:

When subclass object is created memory allocated for superclass object in association with subclass object. So with the subclass reference variable it is possible to access that memory.

Which of the following is a deprecated way to read input from standard input?

  1. Using scanner

  2. Using DataInputStream

  3. Using BufferedReader

  4. All of the above

  5. None of the above


Correct Option: B
Explanation:

This method raises deprecation warning.

Which of the following statements is TRUE about Java interfaces?

  1. It is not possible to implement interface in more than one class.

  2. An interface should not have any members except abstract methods.

  3. It is not possible to have reference variables for interfaces.

  4. We cannot create object for interface.

  5. If a class implements two interfaces which have the same method names, then the class should implement all the simlar methods in two interfaces twice.


Correct Option: D
Explanation:

No, it is not possible to create an object for an interface because it does not have any implemented functions.

Which of the following is not a checked exception?

  1. IllegalAccessEception

  2. CloneNotSupportedException

  3. ClassNotFoundException

  4. SecurityException

  5. InstantiationException


Correct Option: D
Explanation:

It is an unchecked exception.

Which of the following is the method in 'Cloneable' interface?

  1. Copy()

  2. Clone()

  3. toString()

  4. finalize()

  5. None of the above


Correct Option: E
Explanation:

Cloneable is the marker interface. It does not contain any methods.

Which of the following statements is/are syntactically wrong?

  1. Stack st=new Stack();

  2. Stack st=new Stack<>();

  3. Stack st<>new Stack();

  4. Queue qq=new LinkedList();

  5. All of the above


Correct Option: C
Explanation:

It is not possible to pass primitive data types as arguments to generic classes.

In which of the following cases will the finally block not be executed after the try block?

  1. If try block does not have any exceptions.

  2. If try block has a return statement.

  3. If exception is not handled in catch block.

  4. If try block has System.exit(0) statement.

  5. All of the above


Correct Option: D
Explanation:

If we have System.exit(0) statement in try block or in case of threads the thread is killed, finally block will not be executed.

In which of the following cases can we serialize a function?

  1. If the class does not implement serializable interface.

  2. If it has transient keyword before it.

  3. If it fails to create objects for 'ObjectOutputStream' and 'FileOutputStram'.

  4. If it is overridden.

  5. If it is static.


Correct Option: D
Explanation:

Correct answer.

Which of the following is not legacy Class/Interface?

  1. HashMap

  2. Properties

  3. Enumeration

  4. Dictionary

  5. Stack


Correct Option: A
Explanation:

HashMap is not legacy class. It was added as a part of collection framework in J2SE 1.2.

Which of the following data types cannot be used with switch statement?

  1. int

  2. float

  3. char

  4. string

  5. none of the above


Correct Option: B
Explanation:

We cannot use float type on switch statement.

Which of the following statements is false about Synchronized and ThreadSafety?

  1. In multithreading, synchronized methods or statements used to fix dirty reading.

  2. In Java, all the legacy classes are threadsafe.

  3. Application consumes more time if it uses synchronized blocks.

  4. In Java, we use Synchronized modifier to make a block as thread safe.

  5. None of the above


Correct Option: E
Explanation:

All the 4 options are true.

What is the output of the above program?

public class Sss
{
public static
void main(String args[])
 {
 byte a=127; a++;
 System.out.println(a);
 }
}

  1. 127

  2. 0

  3. 128

    • 128
  4. Compilation error


Correct Option: D
Explanation:

Byte ranges from -128 to 127. So, when we increment after 127, it will give -128.

What is the output of the above program?

public class A

{

             static int a;

           public static void main(String args[])

             {

             System.out.println(a);

             }

}

 

  1. Compilation error

  2. 0

  3. Runtime error

  4. NullpointerException

  5. None of the above


Correct Option: B
Explanation:

 Instance variables will be initialized by compiler.

- Hide questions