Descriptive Question

Quiz Guidelines

 

Descriptive Question

QID: 
319

Drag and Drop valid operators in boxes.
= operator can be used more than once.
=        +=        *=
public class TestClass
{
public static void main(String[] args)
{
Short k = 9;    
Integer I =9;    
Boolean b = false;
char c = ‘a’;    
String str = “123”;

Descriptive Question

QID: 
300

Complete the code using blue labels on the right so that the ouput will 210.
(You may have some blanks empty.)

public int a= a+offset;
return a;
u.update(a,111);
a= u.update(a,111);
return;
public void
public class Updater

{

                                       update(int a, int offset)

{

                                     

                                     

}

public static void main(String [] args)

{

Updater u= new Updater();

int a = 99;
                                     

System.out.println(a);

}

}

Descriptive Question

QID: 
76

Identify valid modifiers for a top level class and method declarations.

(Assume that the class is not declared in another class)

Descriptive Question

QID: 
55

Based on assumptions and facts, find the output.

Assumption: filename.txt does not exist.

Fact: FileNotFoundException is a child of IOException.

Program:
 

    try {

      File file = new File("filename.txt");

      Scanner sc = new Scanner(file);

      throw new IOException();

    } catch (IOException e) {

      System.out.println("IOException called!!!");

    } catch (FileNotFoundException e) {

      System.out.println("FileNotFoundException called!!!");

    }

 

Descriptive Question

QID: 
54

Predict the output:

public class ThreadSynchronization {

  public static void main(String[] args) throws InterruptedException {
    Object lockObject = new Object();

    Thread t1 = new Thread(new MyRunnableEven(lockObject));
    Thread t2 = new Thread(new MyRunnableOdd(lockObject));
    t1.start();
    t2.start();
  }
}

class MyRunnableEven implements Runnable {

  private Object lockObject;

  MyRunnableEven(Object lockObject) {
    this.lockObject = lockObject;
  }

  @Override
  public void run() {

    for (int i = 0; i <= 10; i = i + 2) {

      synchronized (lockObject) {
        try {
          System.out.println("Even " + i);
          lockObject.notify();
          lockObject.wait();

        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }
  }
}

class MyRunnableOdd implements Runnable {

  private Object lockObject;

  MyRunnableOdd(Object lockObject) {
    this.lockObject = lockObject;
  }

  @Override
  public void run() {

    for (int i = 1; i < 10; i = i + 2) {
      
      synchronized (lockObject) {
        try {
          lockObject.wait();
          System.out.println("Odd " + i);
          lockObject.notify();
          

        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }
  }
}

Pages