• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Packaging Classes Question

 
Cyrus Serrano
Ranch Hand
Posts: 137
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,



just wondering, when i tried to compile a class that has a package statement, it generates 2 class files. For example my source file name is : Form.java, after compilation it will generate:



Form1.class and Form$1.class



Why is there an extra class file with a dollar sign....
 
Martyn Clark
Ranch Hand
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi it's not because you have the the file in a package. You get two files when you have created a source file with an inner class, When you create a class with an inner class, two files will be created when you compile the source file the inner class being the one with the dollar sign.
 
Cyrus Serrano
Ranch Hand
Posts: 137
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for the reply, but there are no inner classes in my program, here is a code snippet of one of my class files:

package com.StiCalJava.event;

import java.awt.*;
import java.awt.event.*;

public class Form2 extends Frame
{
public Form2(String str)
{
super(str);
setSize(300,300);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);

setVisible(true);
}
}



it thus, generate 2 class files Form2.class and Form2$1.class
Is there an inner class in my program.. thanks
 
Peter Chase
Ranch Hand
Posts: 1970
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code contains an anonymous inner class, which is derived from WindowAdapter.

Note that the class file is $1 because the inner class is anonymous. If you had a named inner class it would be $NameOfInnerClass.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic