How to extends Abstract Inner Class in java -
i confused if
abstract class a{method();method2();}
and other class b
have inner class c
class b{abstract class c{method(){//body}}}
and question how extends class c b/c abstract class must extends else unused class.
first, let's make simpler - has nothing android directly, , don't need a
class @ all. here's want:
class outer { abstract class inner { } } class child extends outer.inner { }
that doesn't compile, because when create instance of child
need provide instance of outer
inner
constructor:
test.java:6: error: enclosing instance contains outer.inner required class child extends outer.inner { ^ 1 error
there 2 options can fix this:
if don't need refer implicit instance of
outer
inner
, makeinner
static nested class instead:static abstract class inner { }
you change
child
accept reference instance ofouter
, , use that callinner
constructor, uses surprising syntax, works:child(outer outer) { // calls inner constructor, providing // outer containing instance outer.super(); }
note these alternatives - should pick 1 want based on whether or not inner class needs inner class.
Comments
Post a Comment