Can variables be abstract
in Java? Do constructor support abstract
variables? I am not sure but I think the constructor supports static variables. Please clarify my doubt.
No you cannot. When you declare a variable you declare an instance of the class/struct you specified. Abstract classes cannot be directly instantiated.
Abstract implies that the abstract methods within abstract classes must be coded. A variable cannot be coded because it is a primitive or reference that can only be assigned a value.
Java doesn't support abstract properties, if you try to mark a class property as abstract, you get a compilation error. In this tutorial, we introduce 2 ways for defining abstract properties which are set by subclasses without using the abstract keyword.
In java only classes and methods can be abstract. Variable declarations cannot. However you can have variable declarations whose types are abstract. See example:
public abstract class MyClass { // allowed
public abstract myMethod(); // allowed
public MyClass instance; // allowed
public abstract MyClass instance; // NOT ALLOWED!!
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With