+ 4
Can you implement an abstact method without extending it class ?
9 odpowiedzi
+ 10
Not really. But you can use an anonymous class that implements the abstract method to avoid a boilerplate class.
Something like
AbstractClass clazz = new AbstractClass(){
void method(){
// your implementation
}
};
clazz.method(); // works
+ 8
Mind To Machine 🤖😎
Nice. So writing this reply was a waste of time 😑
+ 7
If a class have abstract methods, then the class should also be abstract using abstract keyword, else it will not compile.
+ 7
No is the correct answer 🙄
The anonymous class extends the abstract class by implementing its methods. You just spare the extends keyword.
+ 1
i knew that😉
+ 1
Tashi N i was merely trying to see if someone would say no, so i can say what you said😊
+ 1
Tashi N oh...i see
0
honestly the idea of instintiating an abstract class corrupts the purpose. can you hack it? sure. however, if you find yourself needing to implement an abstract class, then you either need to rethink making it abstract and maybe changing your design. or maybe you need to rethink how you are using it. typically abstract classes are designed that way for a reason. if they contain functionality that uou need then maybe you should go more of a composition route than an inheritance. just food for thought.
0
Why we mast to ensign the class, if we out of print only one string or without out of printing?