This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract Class Within an Interface

 
Amrit Kashyap
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correction. You could use an anonymous inner class.
 
Amrit Kashyap
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic