JAVA
Why java is platform independent?
The most unique feature of java is platform independent. In any programming language source code is compiled in to executable code . This cannot be run across all platforms. When javac compiles a java program it generates an executable file called .class file. Class file contains byte codes. Byte codes are interpreted only by JVM’s…
What is the difference between abstract class and interface ?
Abstract Class VS Interface Sr. Abstract Class Interface 1 Abstract class can contain abstract methods, concrete methods or both Interface contains only abstract methods 2 Except private we can have any access specifier for methods in abstract class. Access Specifiers for methods in interface must be public 3 Except private variables can have any access…
Difference between method overloading and method overriding in java ?
Method Overloading VS Method Overriding Sr. Method Overloading Method Overriding 1 Method Overloading occurs within the same class Method Overriding occurs between two classes superclass and subclass 2 Since it involves with only one class inheritance is not involved. Since method overriding occurs between superclass and subclass inheritance is involved. 3 In overloading return type…
What is super keyword in java ?
Variables and methods of super class can be overridden in subclass . In case of overriding , a subclass object call its own variables and methods. Subclass cannot access the variables and methods of superclass because the overridden variables or methods hides the methods and variables of super class. But still java provides a way…
What is method overriding in java ?
If we have methods with same signature (same name, same signature, same return type) in super class and subclass then we say subclass method is overridden by superclass. When to use overriding in java If we want same method with different behavior in superclass and subclass then we go for overriding. When we call overridden…
How to call one constructor from the other constructor ?
With in the same class if we want to call one constructor from other we use this() method. Based on the number of parameters we pass appropriate this() method is called. Restrictions for using this method : 1)this must be the first statement in the constructor 2)we cannot use two this() methods in the constructor
What are static blocks and static initializers in Java?
Static blocks or static initializers are used to initialize static fields in java. We declare static blocks when we want to initialize static fields in our class. Static blocks gets executed exactly once when the class is loaded. Static blocks are executed even before the constructors are executed
JAVA INTERVIEW QUESTIONS
JAVA INTERVIEW QUESTIONS