绝对可以!!
class A{
  private B b = new B();
  public A(){}
  public void printA(){
    b.printB();
    System.out.println("a");
  }
}class B{
  private A a = new A();
  public B(){}
  public void printB(){
    a.printA();
    System.out.println("b");
  }
  public static void main(String[] args){
   A a = new A();
   a.printA();
   B b = new B();
   b.printB();
  }
}

解决方案 »

  1.   

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;public class index extends JFrame 
    {
    JDesktopPane desktop = new JDesktopPane();
    JInternalFrame jf1;
    int i=5;
    int j=5;

    index(String title)
    {
    super(title);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    JMenuBar mb = new JMenuBar();
    JMenu file = new JMenu("文件");
    JMenuItem openfile = new JMenuItem("open");
    openfile.addActionListener(new ActionListener()  {
    public void actionPerformed(ActionEvent e)
    {
    openfile_actionPerformed(e);
    }
    });
    file.add(openfile);
    mb.add(file);
    setJMenuBar(mb);
    getContentPane().add(desktop);
    setSize(600,400);
    setVisible(true);

    } public void openfile_actionPerformed(ActionEvent e)
    {
    jf1 = new JInternalFrame("aa",true,true,true,true);
    jf1.setSize(100,75);
    jf1.setLocation(i,j);
    i+=20;j+=20;
    if(i>120){i=5;j=5;}
    jf1.setVisible(true);
    desktop.add(jf1);
    }
    public static void main(String[] args) 
    {
    new index("aa");
    }
    }
      

  2.   

    你贴这段代码作什么?没有问题呀!
    21cnfox
      

  3.   

    是可以的,只不过弄不好堆栈溢出而已,自己动手试一下就知道了
    比如 Kick_hotdog(khd) 老兄的代码d:\myJavaTest\> java B
    Exception in thread "main" java.lang.StackOverflowError
            at B.<init>(B.java:11)
            at A.<init>(B.java:2)
                ......
                ......
            at B.<init>(B.java:11)
            at A.<init>(B.java:2)