can we declare variable in abstract class code example

Example 1: Can you add instance or static variables into abstract class

Yes, we can add instance or static variables into abstract classes

Example 2: can a variable be declared in abstract

abstract class Parent {
   static void display() {
      System.out.println("Static method in an abstract class");
   }
   static int x = 100;
}
public class Example extends Parent {
   public static void main(String[] args) {
      Parent obj = new Example();
      obj.display();
      System.out.print(Parent.x);
   }
}

Tags:

Misc Example