Friday, July 31, 2009

Java help please!!?

I am a freshie in java





I have some boubts in this code..


what is the static void f (Letter y)?why is it needed?


what happenes when we call f(x)?


one more question its not there in this code... what is transient in java??





class Letter


{


char c;


}


public class PassObject


{


static void f(Letter y)


{


y.c='z';


}


public static void main(String[]args)


{


Letter x= new Letter();


x.c='a';


System.out.println(+x.c+"to X");


f(x);


System.out.println(x.c+"new X");


}


}

Java help please!!?
static void f (Letter y): this is a void method means it has no output value, and it takes as an argument the object of class Letter


when u call f(x) it calls the letter f with the parameter x, in ur example it will give the value of c to the public member of the class


transient: Transient instance fields are neither saved nor restored by the standard serialisation mechanism. You have to handle restoring them yourself.


check the links below to get more about transient in java
Reply:static mean that the variable will keep the value when leaving the function.





void means there will be no return value.





f is the name of the function





Letter y means you sending in an object Letter and naming it y.





The f function serves to change the 'char c' value of the Letter object you called x in the main function. You need this function to change the value because by default the member elements (char c) are private and can only be accessed by the class.

florist delivery

No comments:

Post a Comment