• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

2 queries.

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can a frame be added to a Container?
Can an anonymous class extend an abstract class?
 
Ranch Hand
Posts: 5399
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ans 1: sorry
ans 2: Yes(I think) annonymous class can extend abstract class
<pre>
AbstractClassName acn = new AbstractClassName {
void method1ToImplementOfAbstractClass(){
S.o.p("I have been implemented by annonymous class");
}
</pre>
I think it should work.
Check it and tell me too
CMIW


------------------
Regards
Ravish
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sartaj Syed:
Can a frame be added to a Container?
Can an anonymous class extend an abstract class?


If Applet be consider as a Container, So the answer is YES.
You can add a frame to an Applet
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
q1:
No, you cannot add a Window (so no Frame, no Dialog) to a container.
But I am wondering why, perhaps I was to fast but I didn't see that in the API documentation.
import java.awt.*;
public class A extends Panel
{
A()
{
add(new Frame("mamuba"));
}
public static void main(String args[]) //2
{
A a = new A();
}
}
and this is what I have obtained at run time
Exception in thread "main" java.lang.IllegalArgumentException: adding a window t
o a container
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at A.<init>(A.java:7)
at A.main(A.java:11)

q2.
Yes, I think that an anonymous class can extend an abstract class, check the following code:

class C
{
public static void doSomething(B b)
{
System.out.println("in c...");
}
}

abstract class B
{
abstract public void f();
}
public class A extends C
{
public static void main(String args[])
{
doSomething(
new B()
{
public void f()
{
System.out.println("bla");
}
}
);
}
}
..Cristian

 
I claim this furniture in the name of The Ottoman Empire! You can keep this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic