hes_daydreaming吧 关注:32贴子:739

回复:手编类代码集 = - 见证咱的进步吧

取消只看楼主收藏回复

回复:49楼
= - 好深奥啊。。。我还没学类中的类呢。。。恩 现在明白了
不过一般继承的话 都不继承超类的吗?
还是说子类不应该调用超类的构造器?


50楼2010-07-16 10:18
回复
    回复:51楼
    这就明白了 代表类中的类是类里面私有的。。。但是要生成class的类因为主类要调用。。。所以必须public。。。对吧


    52楼2010-07-16 10:21
    回复
      回复:53楼
      = - ! 不调用它报错啊。。。这是怎么回事


      55楼2010-07-16 10:22
      回复
        回复:56楼
        构造器不就是通过形参去制造实例对象的东西吗。。。是吧


        58楼2010-07-16 10:24
        回复
          private class Cat extends Animal {
             private String legs ;
             public Cat (String color,String name,String legs){
            
              this.legs = legs ;
          }
          public String getLegs(){
               return legs ;
          }
             
          }
          这个是子类
          private class Animal{
             private String color;
             private String name ;
             public Animal(String color,String name){
               
               this.color = color ;
               this.name = name ;
          }
             public String getColor(){
                return color ;
          }
             public String getName(){
                return name ;
          }
          }
          父类
          然后主类还是上边那个AnimalTest


          59楼2010-07-16 10:25
          回复
            = - 当然 类的属性是public 我忘了改了


            60楼2010-07-16 10:26
            回复
              = - 恩 书上是说 不写的话 默认调用父类的无参构造器 如果没有无参构造器就会报错。。。


              63楼2010-07-16 10:34
              回复
                回复:62楼
                呵呵 没什么关系 你是我师傅~~~能帮我我已经很感谢了!


                64楼2010-07-16 10:35
                回复
                  好的好的 以后还有很多问题要问呢!


                  66楼2010-07-16 10:36
                  回复
                    package a;
                    import java.awt.*;
                    import java.awt.event.*;
                    import javax.swing.*;
                    public class Cat{
                         private static void creatAndShowGUI(){
                             JFrame frame = new JFrame("Fcuk!");
                             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                             JMenuBar greenMenuBar = new JMenuBar();
                             greenMenuBar.setOpaque(true);
                             greenMenuBar.setBackground(new Color(248,165,127));
                             greenMenuBar.setPreferredSize(new Dimension(200,20));
                             JLabel yellowLable = new JLabel();
                             yellowLable.setOpaque(true);
                             yellowLable.setBackground(new Color(248,213,131));
                             yellowLable.setPreferredSize(new Dimension(200,180));
                             frame.setJMenuBar(greenMenuBar);
                             frame.getContentPane().add(yellowLable,BorderLayout.CENTER);
                             frame.pack();
                             frame.setVisible(true);
                            
                         }
                         public static void main(String [] args){
                             javax.swing.SwingUtilities.invokeLater(new Runnable(){
                                 public void run(){
                                     creatAndShowGUI();
                                
                                 }
                             });
                            
                         }
                    }


                    67楼2010-08-06 09:08
                    回复
                      import java.io.FileInputStream;
                      import java.io.FileNotFoundException;
                      import java.io.FileOutputStream;
                      import java.io.IOException;
                      public class Test {
                           public static void main(String []args){
                               int count,n=512;
                               byte [] buffer = new byte [n];
                               try {
                                   System.out.print("输入文字!");
                                   count = System.in.read(buffer);
                                   FileOutputStream os = new FileOutputStream("a.txt");
                                   os.write(buffer,0,count);
                                   os.close();
                                   System.out.print("保存成功!");
                               } catch (IOException e) {
                                   // TODO 自动生成 catch 块
                                   e.printStackTrace();
                               }
                               try {
                                   FileInputStream ak = new FileInputStream("a.txt");
                                   while((ak.read(buffer,0,n)!=-1 )&& n >0);
                                   {
                                       System.out.print(new String(buffer));
                                   }
                                   System.out.println();
                                   ak.close();
                               } catch (FileNotFoundException e) {
                                   // TODO 自动生成 catch 块
                                   e.printStackTrace();
                               } catch (IOException e) {
                                   // TODO 自动生成 catch 块
                                   e.printStackTrace();
                               }
                                  
                              
                           }
                      }
                      IO字节流练习


                      69楼2010-09-18 12:35
                      回复
                        public class Test implements Runnable {
                             public Test(){
                                
                             }
                             public void run(){
                             int a = 0;
                             for(a = 0;a<100;a++){
                                 try {
                                     Thread.sleep(1000);
                                     System.out.print(a);
                                     System.out.println();
                                 } catch (InterruptedException e) {
                                     // TODO 自动生成 catch 块
                                     System.out.print("被打扰,终止!");
                                    
                                 }
                                
                             }
                             }
                            
                            
                        }
                        public class RunDemo {
                             public static void main (String [] args) throws InterruptedException{
                                 System.out.print("线程启动中……");
                                 Thread t = new Thread(new Test());
                                 t.start();
                                 System.out.print("waiting....");
                                 System.out.println();
                                 while(t.isAlive()){
                                     System.out.print("still alive....");
                                     System.out.println();
                                     t.join(1000);
                                 }
                                
                             }
                        }
                        


                        70楼2010-09-20 09:19
                        回复