• 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

Anonymous Class

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q4.
1 import java.applet.Applet;
2 import java.awt.*;
3 import java.awt.event.*;
4 public class hello4 extends Applet {
5 public void init(){
6 add(new myButton("BBB"));
7 }
8 public void paint(Graphics screen) {
9 }
10 class myButton extends Button{
11 myButton(String label){
12 super(label);
13 }
14 public String paramString(){
15 return super.paramString();
16 }
17 }
18 public static void main(String[] args){
19 Frame myFrame = new Frame(
20 "Copyright Amit");
21 myFrame.setSize(300,100);
22 Applet myApplet = new hello4();
23 Button b = new Button("My Button");
24 myApplet.add(b);
25 b.setLabel(b.getLabel()+"New");
26 myButton b1 =(new hello4()).new myButton("PARAMBUTTON");
27 System.out.println(b1.paramString());
28 myFrame.add(myApplet);
29 myFrame.setVisible(true);
30 myFrame.addWindowListener(new WindowAdapter(){
31 public void windowClosing(WindowEvent e){
32 System.exit(0);}});
33 }
34 } //End hello4 class.
In the code if you compile as "javac hello4.java" following files will be generated.
a)hello4.class, myButton.class,hello41.class
b)hello4.class, hello4$myButton.class,hello4$1.class
c)hello4.clas,hello4$myButton.class
The answer given is (b).
The first 2 .class files are of the top level "class hello4" & the inner "class myButton" respectively .The third class seems to be an "anonymous class" but at which line is it declared .
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
GOD. I hope the real questions arent this long! we only have 90 minutes for 59 questions. I will read it now.
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
lines 31 and 32.
sorry i took so long but i had to read it all cause the program is rather clever.
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
lines 31 and 32.
sorry i took so long but i had to read it all cause the program is rather clever.
 
Savio Mascarenhas
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Randall Twede:
lines 31 and 32.
sorry i took so long but i had to read it all cause the program is rather clever.


Thanks Randall
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
im sorry i was lagging
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i will remember this. on the test, no matter how interesting the example is, read the possible answers first!
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
specially if the program is very interesting read the answers first
reply
    Bookmark Topic Watch Topic
  • New Topic