Interview Questions

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 1749
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 1632
Q:

What is the use of tostring() method?

Answer

If we print any object by using println() or print() methods.


The println() or print() methods internally calls tostring() method and prints the return value of toString() method.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1462
Q:

why protected modifier?

Answer

Outside the package if any other class other than JVM calls the finalize method our class then it is not allowed

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1927
Q:

What is abstract method?

Answer

abstract method is a method declared with abstract modifier but  with out body.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1562
Q:

Why interface data is static?

Answer

Interface data is static data why bcoz interface supports multiple inheritance.


if inteface data is non-static then there is chance for replication of the data (bcoz of replication of data ambiguity problem occurs )

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1530
Q:

Why interface data is final?

Answer

bcoz interface does not contains any initializers and constructors to initialize its data members.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1737
Q:

Why interface data is public?

Answer

to access non-public data outside class getter methods be defined but we cannot define a  method inside interface we can declared a method inside interface.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 4282