| Author |
Abstract Class Within an Interface
|
Amrit Kashyap
Ranch Hand
Joined: Apr 23, 2006
Posts: 44
|
|
hi friends, i want a solution for the below given scenario: interface NestedClassInterface { public void show(); abstract class a1 { public void show1(){System.out.println("hello");} public abstract void show2(); }; } class abc implements NestedClassInterface { public void show() { System.out.println("bye"); } //insert code here to define show2 method of abstract class a1 public static void main(String[] args) { new abc().show(); //insert code here to accesss show2 or show1 method //of abstract class a1 } } My question is that : 1. How can i give definition to abstract class a1's abstract method show2 and access that afterwards? 2. I don't want a solution like following: class someClass extends NestedClassInterace.a1 { //rest of code goes here } I want solution only for above given scenario. thanks in advance....
|
 |
Manfred Klug
Ranch Hand
Joined: Jun 04, 2007
Posts: 377
|
|
Hi Devashish, based on the code insertion points, I think the only possibility you have is to insert a new class.
|
 |
Manfred Klug
Ranch Hand
Joined: Jun 04, 2007
Posts: 377
|
|
|
Correction. You could use an anonymous inner class.
|
 |
Amrit Kashyap
Ranch Hand
Joined: Apr 23, 2006
Posts: 44
|
|
hi manfred, are you saying something following type of thing for this: a1 obj= new a1(){public void show2(){System.out.println("show2");}}; I've done that already, but i want to know whether some other alternative exist in addition to these two?
|
 |
Manfred Klug
Ranch Hand
Joined: Jun 04, 2007
Posts: 377
|
|
Originally posted by Devashish Roy: are you saying something following type of thing for this: a1 obj= new a1(){public void show2(){System.out.println("show2");}}; I've done that already
Yes.
|
 |
 |
|
|
subject: Abstract Class Within an Interface
|
|
|