English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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");
}
}

2007-03-09 18:01:59 · 2 answers · asked by Database 2 in Computers & Internet Programming & Design

2 answers

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

2007-03-09 19:00:58 · answer #1 · answered by abd 5 · 0 0

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.

2007-03-09 23:24:44 · answer #2 · answered by Tasm 6 · 0 1

fedest.com, questions and answers