Manoj
January 12th, 1999, 02:29 PM
HI. I am a C++ programmer mingrating to Java
I have this query..Does Java support pass by value or pass by reference.
Following code suggests that Java supports Pass by reference as it calls the "callme " function from the derieved
class. But then it calls the constructor of the base class also which suggests that it makes a copy of base class...It
means its pass by value..
Please help
class Base {
Base(){
System.out.println("I am in base class constructor ");
}
void callme(){
System.out.println("I am in base class");
}
}
class Derieved extends Base {
void callme(){
System.out.println("I am in derieved class");
}
}
class dispatch {
public static void main(String args[]) {
Derieved dd = new Derieved() ;
fff(dd);
}
}
static void fff(Base bb){
bb.callme();
}
}
OUTPUT is
I am in base class constuctor
I am in base derieved class
I have this query..Does Java support pass by value or pass by reference.
Following code suggests that Java supports Pass by reference as it calls the "callme " function from the derieved
class. But then it calls the constructor of the base class also which suggests that it makes a copy of base class...It
means its pass by value..
Please help
class Base {
Base(){
System.out.println("I am in base class constructor ");
}
void callme(){
System.out.println("I am in base class");
}
}
class Derieved extends Base {
void callme(){
System.out.println("I am in derieved class");
}
}
class dispatch {
public static void main(String args[]) {
Derieved dd = new Derieved() ;
fff(dd);
}
}
static void fff(Base bb){
bb.callme();
}
}
OUTPUT is
I am in base class constuctor
I am in base derieved class