8
Q:

void waitForSignal() {

Object obj = new Object();

synchronized (Thread.currentThread()) {

obj.wait();

obj.notify();

}

}

Which statement is true?

A) This code can throw an InterruptedException. B) This code can throw an IllegalMonitorStateException.
C) This code can throw a TimeoutException after ten minutes D) All the above

Answer:   B) This code can throw an IllegalMonitorStateException.



Explanation:

It will throw  IllegalMonitorStateException.

Subject: Java
Job Role: IT Trainer
Q:

In a class if private data member is declared then how to get value of that data member?

Answer

By using method.


The method used to get the data is called getter method.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1527
Q:

In a class if private data member is declared then how to set data to that private data member?

Answer

By using method.


The method used to set the data is called setter method.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1564
Q:

What is the differnce among public, protected and package access data?

Answer

If we are not using packages and if we are not using inheritance then there is no difference among public, protected and package access data.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1697
Q:

When this. non-static datamember is compulsory inside non-static method

Answer

Whenever there is local- variable/parameter inside the method with same name as data member.


Ex:


Class Sample {


 int a;


  void show() {


   int a=5;


   system.out.println(a); // 5


   system.out.println(this.a);//23


  }


}


class MainApp {


  Public static void main(String[] args) {


  Sample s = new Sample();


   s.a = 23;


   s.show();


   }


}


 

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1916
Q:

What is stored in the 'this' reference?

Answer

This is a keyword and used as reference to Current object address in java. 


It means by using which object the method is called that object hashcode is stored inside the 'this'.

Report Error

View answer Workspace Report Error Discuss

Subject: Java
Job Role: Analyst

0 1523
Q:

Why static method can not call non static method of the same class?

Answer

bcoz the static method does not contains the 'this' reference.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2457
Q:

How to assign address to the reference?

Answer

ClassName refName = new ClassName();


or


ClassName refName;


refName = new ClassName();

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1560
Q:

What is the syntax to create the object?

Answer

new ClassName();


This expression creates object in heap area and returns that obj address. Here JVM creates object but JVM does not returns object original address. JVM returns duplicate address, duplicate address is also called as hashcode. 

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1614