• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Abstract Class Within an Interface

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Happily living in the valley of the dried frogs with a few tiny ads.
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic