RETURNING OBJECTS

This section of JAVA contains source codes of many different type of Java Programs to learn the JAVA Basics. These Programs are well formatted and easy to understand.

RETURNING OBJECTS

Postby aman_1982_2006 on September 4th, 2008, 5:47 am

Code: Select all
//program to show returning objects
class student
{
   int age;
   double fee;
   void data()
   {
      age=20;
      fee=1375.20;
   }
   student getdata(student s)
   {
      student s1=new student();
      s1.age=s.age+2;
      s1.fee=s.fee+2;
      return s1;
   }
   void disp()
   {
      System.out.println(age);
      System.out.println(fee);   
   }
}
class mn1
{
   public static void main(String ar[])
            {
      student s1=new student();
      s1.data();
      s1.disp();
      student s2=new student();
      s2.disp();
      student s3=new student();
      s3=s2.getdata(s1);
      s3.disp();

   }
}
aman_1982_2006
 
Posts: 9
Joined: August 30th, 2008, 6:18 am

Return to Java

Who is online

Users browsing this forum: No registered users and 0 guests