Youtube Channel

Intresting facts of java

Why Object is super class in java ?

Ans :  As the java.lang.Object contains some predefined method which are conmanly used by the other classes . so by not proving this methods to those classes it was better to make it as a super class so that each and every class can access its property.

Diff between Final , Finally and Finalize.?

Final is the keyword or modifier allowed to used with variables, methods and class.
A class declared final cant be extended, A method declared final cant be overridden and a variable declared final its reference is fixed

Finally is used in exception handling where it executes always whether exception occurs or not . it contains the releasing codes mainly like closeting  a file or closing  a connection etc

Finalize is a method which is called by the garbage collector before destroying the the reference for clean up related tasks.


What is transient ?

Its the modifier used with the variable in serialization process , when we don't want a variables value to be written in a file so we mark the variable as transient so that instead of going originally value only default value for that type of variable  is written

Is there multiple inheritance in java ?
No, java does not supports multiple inheritance.

What is difference between abstract class and interface in java ?

When we dont know about implementations details but we have the requirement we go for interface.
But when we have partial knowlede about the implementaion we go for abstract class.


Is it possible to mark abstract class as final ?
Not possible , because if we mark the class as final it cant be extended but the abstract classes are meant for extended so it is not allowed in java.

Can we create final method in abstract class ?
Yes it is possible to create a final method inside a abstract class.


Can we mark a transient variable as final or static or both ?
Yes it is possible , but it is not required to do so because if we mark them as static or final its original value gets written in file so there is no use of transient variable

Difference  between error and exception ?

An unexpected event that interrupts the flow of a program is exception which can be recovered.
While an error can be caused due to lack of system resources or it is non recoverable.

Next PostNewer Post Previous PostOlder Post Home