what are static blocks and static initalizers in Java ?
answer : Static blocks or static initializers are used to initalize static fields in java. we declare static blocks when we
want to intialize 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.
answer : Static blocks or static initializers are used to initalize static fields in java. we declare static blocks when we
want to intialize 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.
❤1
What's the base class in Java from which all classes are derived
Anonymous Quiz
53%
java.lang.object
20%
Java.util.object
8%
java.lang.base
20%
Both A and C
How to call one constructor from the other constructor ?
answer : 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
answer : 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
👍1
Learn C Programming, 2nd Edition (Jef.).pdf
15 MB
Learn C programming
Jeff Szuhay, 2022
Jeff Szuhay, 2022
115_Java_Interview_Questions_and.pdf
946.4 KB
✅ Important Java Interview Preparation Questions with Answers 🚀
⚠️ Very Very Important for Technical Interviews
⚠️ Very Very Important for Technical Interviews
Why a constructor cannot be final in Java?
Ans: If a method is marked as final it means we do not want any class to override it. As per Java Language Specification, a constructor cannot be overridden. So, there is no use in declaring a constructor as final.
Ans: If a method is marked as final it means we do not want any class to override it. As per Java Language Specification, a constructor cannot be overridden. So, there is no use in declaring a constructor as final.
What is method overriding in java ?
If we have methods with same signature (same name, same arguments, same return type) in super class
and subclass then we say
subclass method is overridding method in superclass.
When to use overriding in java
If we want same method with different behaviour in superclass and subclass then we go for overriding.
When we call overridden method with subclass reference subclass method is called hiding the superclass
method.
If we have methods with same signature (same name, same arguments, same return type) in super class
and subclass then we say
subclass method is overridding method in superclass.
When to use overriding in java
If we want same method with different behaviour in superclass and subclass then we go for overriding.
When we call overridden method with subclass reference subclass method is called hiding the superclass
method.
👍1
What is functional Interface ?
An Interface that contains exactly one abstract method is known as functional interface. It can have any number of default, static methods but can contain only one abstract method. It can also declare methods of object class. Functional Interface is also known as Single Abstract Method Interfaces or SAM Interfaces. It is a new feature in Java, which helps to achieve functional programming approach.
An Interface that contains exactly one abstract method is known as functional interface. It can have any number of default, static methods but can contain only one abstract method. It can also declare methods of object class. Functional Interface is also known as Single Abstract Method Interfaces or SAM Interfaces. It is a new feature in Java, which helps to achieve functional programming approach.
👍1