Thursday, April 25, 2019

Java Basic Interview Questions

Interview Questions Main Method

Q-  What is the main method in Java?
Q-  How does JVM call main method?
Q-  Why main method is static?
Q-  Can we overload main method in Java ?
Q-  Can we override main method in Java ?
Q-  What will happen if we declare main() method as non-static ? or What will happen if we remove static keyword from main method?
or Can we declare main() method with different access modifier other than public ?
Q-  Can we change return type of main() method ?
Q-  Can a main () method be declared private?
Q-  Can a main () method be declared final?
Q-  Can we define a class without main method ?
Q-  Can we declare static variable in main method?
Q-  Why derived class destructor is called first?
Q-  Why is main () method special in a Java program?
Q-  Is main method necessary in Java?
Q-  Could you run the java program without main method?
Q-  Why main method is executed first in Java?
Q-  Is main method compulsory in Java?
Q-  Can we have two main methods in Java?
Q-  Can we write main method in abstract class?
Q-  Can we call main method in Java? or Can we call main() from another function in Java? 
Q-  How do you call a main method from another class in Java?
Q-  Can we have main method in interface?
Q-  Can we have a main() in an interface and different implementations?

Interview Questions On Association,  Composition And Aggregation  

Q- Inheritance vs Composition ? or What is the benefit of composition over inheritance? or Is composition better than inheritance?
Q- Composition Vs Aggregation ? or What is aggregation and composition in OOP?
Q- Composition Vs Aggregation Vs Association
Q- Why and when we have to use inheritance?

Interview Questions On Static keyword 

Q-  Can we override the static method?
Q-  Can static class be inherited?
Q-  Can static method be final?
Q-  Can static class have constructor?
Q-  Can a static variable be changed?
Q-  Can static class have non static methods?
Q-  Can object be static?
Q-  Can a static variable be initialized in a constructor?
Q-  Can static and final come together?
Q-  Can we create object of static class?

Interview Questions On Constructer 

Q-  Can we inherit constructor?
Q-  Why constructor is never inherited?
Q-  Which constructor is called first in inheritance?
Q-  Why destructors are called in reverse order?
Q-  Can we declare constructor as final?

Q-  When should we use a static class?
Q-  Why Singleton class is sealed?
Q-  What is Sealed class in java ?
Q-  What is the order of objects destroyed in the memory?
Q-  Can interface have constructor in Java?

Q-  How to prevent Singleton Class from Serialization, Cloning and Reflection?


Note :- Static variable, final methods and instance variable can't be override.

No comments:

Post a Comment