Accessing variables of an object of a particular class through a different class within the construc

Posted by Haxed on Stack Overflow See other posts from Stack Overflow or by Haxed
Published on 2010-05-28T18:21:20Z Indexed on 2010/05/28 18:32 UTC
Read the original article Hit count: 243

Filed under:
|
class Student {

  private String name;

  public Student(String name){
         this.name = name;
  }
  public String getName(){
         return name;
  }
}

class StudentServer {


   public StudentServer(){

          Student[] s = new Student[30];
          s[0] = new Student("Nick");

          System.out.println(s[0]); // LINE 01:But this compiles, although prints junk

          System.out.println(s[0].getName()); // LINE 02:I get a error called cannot find symbol
   }

  public static void main(){
         new StudentServer();
  }
}

Hey, there are two lines, I want the reader to focus on, the first line prints junk as usual, but suprizingly the second one gives me an error. Do you know why ?

Many Thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about object