Difference between Class.forName() and newInstance() in java Class.forName() returns the Class-Type for the given name. Means that it will return reference to a class and load the available all static blocks not instance methods. if you are interested only in the static block of the class , the loading the class only would do , […]
Category: Java Basics
Java basic interview questions and answers are very important before going to Java interview. So read the following questions and answers and refresh our mind.
What is the difference between Static Block and Constructor placed in a class? Static Block Static block of a java class executes for only one time when JVM loads the class irrespective of whether object is created for class or not and whether java class is having main method or not. So static block […]
Explain with example to describe when to use abstract class and interface? Consider a scenario where all Cars will have 4 tyres and other features can be different. In this case any subclass of Car has to have 4 tyres. This is a case where abstract class will be used and a default implementation for […]
What is difference between abstract class and interface? Abstract class may or may not be contain abstract methods but a class should be called as abstract when it contains at least one abstract method. It can also contain n numbers of concrete method. Interface can contain only abstract ( non implemented) methods. The abstract […]
What is the difference between static and instance methods? Instance method belongs to the instance of a class therefore it requires an instance before it can be invoked, whereas static method belongs to the class itself and not to any class instance so it doesn’t need an instance to be invoked. Instance methods use dynamic […]