+ 1
Can we create object for an abstract class ?
If yes tell me how ?
5 ответов
+ 2
No. Abstract class doesnot have full implementations for all of its methods so you can't..
+ 1
Just answered couple of hours ago.
https://www.sololearn.com/Discuss/2176352/?ref=app
Use the search bar for similar questions because they might have been answered already.
0
yes, if it implements its abstract methods
abstract class A {
abstract void method();
}
public class Program {
public static void main(String[] args) {
A a = new A() {
void method(){}
};
}
}
0
zemiak You are creating an instance of the anonymous subclass of the abstract class. Here you have given a reference to the abstract class which holds your subclass object.
This is different from an actual abstract class being instantiated directly, which is not possible.
0
yes you are right, theoretically it is different, I thought about it from more practical point of view,
the question does not specify that the creation must be directly.