日期:2014-05-20  浏览次数:20578 次

No enclosing instance of type ...
小弟新学java,请教这段代码哪里出问题了,谢谢啊

public   class   College   {

public   class   Student{
String   sname=null;
String   sid=null;
  Student(){}
 
void   Setname(String   name){
this.sname=name;
}
void   nprint(){
System.out.println( "sname "+   sname);

}
}
           
    public   class   Mstudent   extends   Student{
      String   mname=null;
      void   setmname(String   name){
        this.mname=name;
     
      }
    void     mprint(){
    System.out.println( "Mname "+mname);
 
    }
    }
      public   class   Ustudent     extends   Student{
        String   fname=null;
        void   setfname   (String   name){
        this.fname=name;
        }
        void   fprint(){
          System.out.println( "Fname "+   fname);
        }
      }
     

    public   static   void   main(String[]   args   ){
 
        College   s=new   College();
      Student   s1=   new   Student();
      s1.Setname( "zhou ");
      s1.nprint();
   
    }
}



------解决方案--------------------
public class College { 

public static class Student{ 
String sname=null; 
String sid=null; 
Student(){} 
  
void Setname(String name){ 
this.sname=name; 

void nprint(){ 
System.out.println( "sname "+ sname); 




public class Mstudent extends Student{ 
String mname=null; 
void setmname(String name){ 
this.mname=name; 


void mprint(){ 
System.out.println( "Mname "+mname); 
  


public class Ustudent extends Student{ 
String fname=null; 
void setfname (String name){ 
this.fname=name; 

void fprint(){ 
System.out.println( "Fname "+ fname); 




public static void main(String[] args ){ 
  
College s=new College(); 
Student s1= new College.Student(); 
s1.Setname( "zhou "); 
s1.nprint(); 




红色是我加上的,这样应该可以了,呵呵