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

Final parameter in java

In java, final parameter is a parameter which is declared with final keyword. Its value can not be changed. Example class FinalParameterTest{   void show(final String website){ System.out.println("website = " + website); } } public class Main { public static void main(String args[]){ //creating object of FinalParameterTest Class FinalParameterTest obj = new FinalParameterTest(); obj.show("w3schools.com"); } … Read more

Static blank final variable in java

In java, static blank final variable is a variable which is declared with final keyword but not initialised at declaration time. It can only be initialised in static block. Example class StaticBlankFinalTest{ //static blank final variable static final String website;   static{ website = "w3schools.com"; System.out.println("website = " + website); } } public class Main … Read more

Blank final variable in java

In java, blank final variable is a variable which is declared with final keyword but not initialised at declaration time. Blank final variables are initialised at the object creation time by constructor and they can’t change after that. Example class BlankFinalTest{ //blank final variable final String website;   BlankFinalTest(String website){ this.website = website; System.out.println("website = … Read more

Final class in java

In java, a class declared with final keyword is called as final class. Inheritance is not possible with final class. Example final class Show{ //final class method public void show(){ System.out.println("Inside final method"); } } class FinalClassTest extends Show{ public void show(){ System.out.println("Inside overridden method of final class"); } } public class Main { public … Read more

Final method in java

In java, final methods are declared with final keyword. We can not override the final methods. Example class Show{ //final method public final void show(){ System.out.println("Inside final method"); } } class FinalMethodTest extends Show{ //try to override final method public void show(){ System.out.println("Inside overridden final method"); } } public class Main { public static void … Read more

Final variable in java

A Final variable in java is declared with final keyword. It can represent a member variable or local variable. The final variables represents the constants in java and normally declared with static keyword. As final variables are constants that’s why they are initialised at the time of declaration and can’t be reassigned. Example class FinalVariableTest{ … Read more

Protected class in java

Yes, we can declare a class as protected but these classes can be only inner or nested classes. We can’t a top-level class as protected because declaring top class as protected will mean that it is accessible to the current package as well as sub packages. Now there’s no concept of sub packages in Java. … Read more

Private abstract method in Java

Private methods are private to the class only. They are not polymorphic in nature i.e. we cannot inherit them, so it makes no sense to make a private method abstract. Making a method abstract means we have to override and implement it in a subclass, but since we can’t override private methods, we can’t make … Read more