Core Java Interview Questions

We know that many of us suffer to get a suitable job in their career. So if you are preparing your job interview for JAVA career , this my help you. Based on the frequent question of time interview; we prepared Q&A article for you.

1. Can we write static block within the method?

Answer:
No. Compiler will give error.
public class Test{
public static void main(String[] args) {
static{
}
}
}
Compiletime Error: Illegal start of expression.


2. Can we write return statement without value in constructors?

Answer: Yes.

public class Test{

        Test(){

                return;

        }

        public static void main(String[] args) {

                {

                        System.out.println(“non static block”);

                }

        }

}


3.What is the difference between static and new keyword?

Answer: 
New keyword is useful for providing memory for non-static data, it is individual, where as static keyword is useful for providing memory static data by default by JVM, it is common for all.

To get full article click here Questions & Answers on Core Java

Latest Articles:

Follow us:

Leave a Reply

Your email address will not be published. Required fields are marked *