Abstraction vs Encapsulation in java

            Encapsulation                Abstraction 1. Encapsulation is a concept for wrapping of data and code into a single unit. 2. Encapsulation is a way of data hiding. 3. Encapsulation is achieved by access modifiers and classes. 4. Encapsulation solve the problem at implementation level. 1. Abstraction is a way to show only essential details to user. … Read more

Static vs dynamic binding in java

            Static binding              Dynamic binding Static binding in Java occurs during compile time. private, final and static methods and variables use static binding and are bonded by compiler Must not have any explicit return type. Static binding uses Type information  i.e. class in Java, for binding. Overloaded methods are bonded using static binding Dynamic binding occurs during runtime. virtual methods are bonded … Read more

can we declare constructor as final in java?

No, we cannot declare constructor as final in java. Java interview questions on final keyword what is final in java? What is final variable in java? What is final method in java? What is final class in java? What is blank final variable in java? What is static blank final variable in java? What is … Read more

Can we change the value of an interface field?

No, we can’t change the value of an interface field because interface fields are final and static by default. Example interface FinalTest{ String website = "w3schools.com"; } public class Main implements FinalTest{ void show(){ System.out.println(website); } public static void main(String args[]){ //creating object of Main Class Main obj = new Main(); obj.show(); } }interface FinalTest{ … Read more

what is the use of final class in java?

A final class is simply a class that can’t be extended. Main use of a final class is to prohibit inheritance in Java. This does not mean that all references to objects of the class would act as if they were declared as final. Java interview questions on final keyword what is final in java? … Read more

Abstract vs final method in java

An abstract method must be overridden in the sub class whereas final method cannot be overridden. Example: abstarct method overridden in subclass abstract class AbstractMethodTest{ abstract void show();   } public class Main extends AbstractMethodTest { void show() { System.out.println("Inside overridden show method"); } public static void main(String args[]){ //creating object of Main Class Main … Read more

can we declare the main method as final?

Yes, we declare the main method as final. public static final void main(String[] args){} Example public class Main { public static final void main(String[] args) { System.out.println("Final main method"); } }public class Main { public static final void main(String[] args) { System.out.println("Final main method"); } } Output Final main methodFinal main method Java interview questions … Read more

Initialize blank final variable in java

Yes. We can initialise blank final variable in java, only in constructor but it should be a non-static blank final variable. Example with non static variable: class BlankFinalInitialization{ //blank final variable final String courseName;   BlankFinalInitialization(String courseName){ this.courseName = courseName; System.out.println("courseName = " + courseName); } } public class Main { public static void main(String … Read more