Tag: programming languages

Questions Related to programming languages

  1. abstract double area() { }

  2. abstract double area()

  3. abstract double area();

  4. abstract double area(); { }


Correct Option: C

Given: 1. public class Threads5 { 2. public static void main (String[] args) { 3. new Thread(new Runnable() { 4. public void run() { 5. System.out.print(”bar”); 6. }}).start(); 7. } 8. } What is the result?

  1. Compilation fails.

  2. An exception is thrown at runtime.

  3. The code executes normally and prints “bar”.

  4. The code executes normally, but nothing prints.


Correct Option: C

AI Explanation

To answer this question, we need to understand the behavior of the code provided.

In the given code, a new thread is created using an anonymous inner class that implements the Runnable interface. The run() method in the inner class is overridden to print "bar". The start() method is then called on the newly created thread to start its execution.

When a thread is started using the start() method, it executes independently in parallel with the main thread. In this case, the newly created thread will execute the run() method and print "bar".

Therefore, the correct answer is:

C) The code executes normally and prints "bar".

  1. Compilation fails.

  2. An exception is thrown at runtime.

  3. The code executes normally and prints “sleep”.

  4. The code executes normally, but nothing is printed.


Correct Option: C
  1. A finalizer may NOT be invoked explicitly.

  2. The finalize method declared in class Object takes no action.

  3. super.finalize() is called implicitly by any overriding finalize method.

  4. The finalize method for a given object will be called no more than

  5. The order in which finalize will be called on two objects is based on


Correct Option: B,D
  1. Inheritance represents an is-a relationship.

  2. Inheritance represents a has-a relationship.

  3. Interfaces must be used when creating a has-a relationship.

  4. Instance variables can be used when creating a has-a relationship.


Correct Option: A,D
  1. The return type for a method can be any Java type, including void

  2. An important principal of object oriented programming is implementation hiding

  3. When you perform mathematical calculations on the unlike data type, java will perform a implicit conversion to unify the types

  4. All the Above


Correct Option: D