Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / JavaBeans / July 2005

Tip: Looking for answers? Try searching our database.

get property of a class

Thread view: 
shoa - 12 Jul 2005 01:27 GMT
Hello

I have simple class Student like this:

-----------------------------------------
class Student{
    String studentName;
    int studentID;
    String studentAddress;

   public Student (String studentName, int studentID, String
studentAddress){
         this.studentID = studentID;
         this.studentAddress = studentAddress;
         this.studentName = studentName;
    }

   public String getStudentName(){
         return this.studentName;
   }
}
-------------------------------------------
Now I create a student object:

    Student aStudent = new Student ("John", 122121, "USA");

I want to have the name of this student Object, so I have two methods:

    //first method
   String studentName= aStudent.studentName;
   //another method
   String studentName = aStudent.getStudentName();

In a simple application like this, two results as the same. I know that the
first method is not correct. Could you please tell me the differences
between two methods and why I should choose method 2.

Many thanks
S.Hoa
shoa - 12 Jul 2005 01:33 GMT
Sorry, I post in wrong place

> Hello
>
[quoted text clipped - 35 lines]
> Many thanks
> S.Hoa


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.