Yes, we can declare local inner class as abstract.
Example
class OuterTest { public void getValue() { int num = 40; // Abstract Local inner Class abstract class AbstractInnerTest { abstract void getRemainder(); } class InnerTest extends AbstractInnerTest { public int divisor; public int remainder; public void getRemainder() { divisor = 3; remainder = num%divisor; System.out.println("Remainder : " + remainder); } } InnerTest innerTest = new InnerTest(); innerTest.getRemainder(); } } public class Main { public static void main(String[] args) { OuterTest outerTest = new OuterTest(); outerTest.getValue(); } } |
Output
Remainder : 1 |
Java interview questions on interface and abstract class
- What is interface in java?
- Can we declare an interface method static in java?
- Can an interface be declared final in java?
- What is marker interface and how we can create it?
- What is difference between abstract class and interface in java?
- What is abstract class in java?
- Why abstract class is used in java?
- Can abstract class have constructors in java?
- Can abstract class be final in java?
- Can we declare local inner class as abstract?