Core Java

What to choose between abstract class and interface if…

Answer to what to choose between abstract class and interface if both contain only abstract methods. This is the frequently asked technical interview question. Here I’m providing two reasons with examples. Let me elaborate the question for your better understanding. You know that interface contains only abstract methods. But, consider the restriction that abstract class […]

What is the use of volatile keyword in java?

Use of volatile keyword in Java – The volatile keyword is used to declare a variable volatile, so, the variable can be accessed directly from the memory not from intermediary cache. For example, If you declare a variable volatile, then it will be directly accessed from the memory where it resides and not from the […]

Can we overload main method in java?

Interview Question – Can we overload main method in java programs, for example in below class Sample, public static void main(String[] args) is given, that is the start point of the program. So, can we write more methods with same name i.e. main (method overloading)? Answer:Yes, we can overload main method in java program. We […]

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 common […]

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 […]

Scroll to top