Category Archives: Core Java Interview Questions

Can a abstract class be declared final? | Core Java Questions

Not possible. An abstract class without being inherited is of no use and hence will result in compile time error.

Posted in Core Java Interview Questions | Leave a comment

What is an Abstract Class and what is it’s purpose? | Core Java Questions

A Class which doesn’t provide complete implementation is defined as an abstract class. Abstract classes enforce abstraction.

Posted in Core Java Interview Questions | Leave a comment

Can we declare a static variable inside a method? | Core Java Questions

Static variables are class level variables and they can’t be declared inside a method. If declared, the class will not compile.

Posted in Core Java Interview Questions | Leave a comment

What is the importance of static variable? | Core Java Questions

static variables are class level variables where all objects of the class refer to the same variable. If one object changes the value then the change gets reflected in all the objects.

Posted in Core Java Interview Questions | Leave a comment

I want to print “Hello” even before main is executed. How will you acheive that? | Core Java Questions

Print the statement inside a static block of code. Static blocks get executed when the class gets loaded into the memory and even before the creation of an object. Hence it will be executed before the main method. And it … Continue reading

Posted in Core Java Interview Questions | Leave a comment

What are the restriction imposed on a static method or a static block of code? | Core Java Questions

A static method should not refer to instance variables without creating an instance and cannot use “this” operator to refer the instance.

Posted in Core Java Interview Questions | Leave a comment

When will you define a method as static? | Core Java Questions

When a method needs to be accessed even before the creation of the object of the class then we should declare the method as static.

Posted in Core Java Interview Questions | Leave a comment

Can a class be declared as static? | Core Java Questions

No a class cannot be defined as static. Only a method,a variable or a block of code can be declared as static.

Posted in Core Java Interview Questions | Leave a comment

How is final different from finally and finalize? | Core Java Questions

final is a modifier which can be applied to a class or a method or a variable. final class can’t be inherited, final method can’t be overridden and final variable can’t be changed. finally is an exception handling code section … Continue reading

Posted in Core Java Interview Questions | Leave a comment

Can you give few examples of final classes defined in Java API? | Core Java Questions

java.lang.String,java.lang.Math are final classes.

Posted in Core Java Interview Questions | Leave a comment