Why method overriding is called runtime polymorphism in Java?

Answer to why method overriding is called runtime polymorphism in java includes very simple code example with explanation, so you can understand easily. Do you think answer is difficult? In fact, it super simple. Read till end. You may read more about method overriding in java with example.   “In Run time polymorphism methods get … Read more Why method overriding is called runtime polymorphism in Java?

Examples where use of Java Static method is Indispensable

Let’s see some examples where use of java static methods are mandatory in the programs. Generally, we use static method where we want to call method without creating an object of the class. Here are examples where we cannot avoid using static methods in java and are indispensable. NOTE: Generally, this question is asked to … Read more Examples where use of Java Static method is Indispensable

Why we need double check in singleton class in java? – Answered

Answer to why we need double check locking in singleton class in Java with thread program example.   Let’s understand first what does double checking means?   Consider the method getInstance() of below singleton class. You will see there are two if conditions to check if the singleton class object is null. So, question is, … Read more Why we need double check in singleton class in java? – Answered

How to create immutable class in java – Simplest Example

Create immutable class in java by making class field final and private, providing getter setter method and returning new object with new data on object modification Technical interview question is that, make a user defined class immutable. Write a simple immutable class and Explain it. also, demonstrate that it is immutable in main program. Note … Read more How to create immutable class in java – Simplest Example

What to choose between abstract class and interface if…

Answer to what to choose between abstract class and interface if both contains only abstract methods. This is the frequently asked technical interview question and two reasons are provided with examples. Elaborating the question for better understanding. You know that interface contains only abstract methods. But, consider the restriction that abstract class has only abstract … Read more What to choose between abstract class and interface if…

What is method signature in Java – Does it include return type?

What is method signature in java ? – Method signature in java includes only method name and parameters. Method return types are not included in method signature. For example, in below class method declaration only “foo(String str)” is the method signature that contains method name and parameters. Return type String should in excluded.   class … Read more What is method signature in Java – Does it include return type?

Why to use Abstract keyword in java language?

Abstract keyword is used to create an abstract class and abstract methods in java programs. Abstract class: Abstract class in java is used as a base class in inheritance relationship. Abstract class have both non-abstract (implemented methods) and abstract (un-implemented methods) that must be overridden by sub classes. Note that If we want to have … Read more Why to use Abstract keyword in java language?

What are methods of object class in java? – with description

Methods of Object class in java with brief descriptions – The java.lang.Object class is the super class of all classes  whether the class is predefined or user defined class. Object class is by default inherited whether we extend explicitly or not. Methods of object class in java : protected native Object clone() throws CloneNotSupportedException public boolean equals(Object … Read more What are methods of object class in java? – with description