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:

why overriding finalize() method?

Answer

If constructor opens the file 


finalize() method closes that file.


 


If constructor opens the connection 


finalize() method closes that connection.


 


To perform finalization operation we must overriding finalize method.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1796
Q:

What is the purpose of overriding toString() method?

Answer

we can override tostring() method to return String representation of our object data

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1936
Q:

What is final method?

Answer

Final method is a method defined in the super class with final modifier.


We cannot overriding final method of super class in the sub class.


EX:


 Class Sample {


   final void funOne() {


   }


   void funTwo() {


   }


}


Class Sub extends Sample {


  void funOne() { // overriding is not allowed


  }


  viod funTwo() { //overriding is allowed


  }


}

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2183
Q:

What is the use of overloading ? or why overloading?

Answer

By using overloading we can add new functionality to the sub class.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1661
Q:

What is the use of overriding?

Answer

- By using method overriding a sub class can change the definition of super class method.


- By using overriding a sub class can modify the functionality of the super class.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1813
Q:

If sub class data member is hiding super class data member then how to access super class data member inside sub class methods?

Answer

use super keyword.


super keyword points immediate super class.


Class Sample {


int a =23;


 }


Class Sub extends Sample { 


 String a = "bablu";


 void show() {


 System.out.println(a); //bablu


 System. out. println(this.a); //bablu


 System. out.println(super.a); //23


}


}


Class Demo {


Public static void main(string[] args) {


sub s = new Sub();


s.show();


}


}


 

Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 3783
Q:

If super class ref is pointing sub class object then by using super class ref is it possible to call sub class newly defined method?

Answer

yes if the method is ovreriding method


no if the method is not overriding method

Report Error

View answer Workspace Report Error Discuss

Subject: Java

134 1686
Q:

What is the use of super call?

Answer

By using super call we can call super class constructors  from sub class constructors and we can initialize super class private data.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1794