| Author |
Aliasing
|
Stephen Silva
Greenhorn
Joined: Jul 12, 2011
Posts: 18
|
|
Aliasing also can happen within method calls, the following program illustrates it. Identify
the problem and modify the program to address the aliasing.
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;
print("1: x.c: " + x.c);
f(x);
print("2: x.c: " + x.c);
}
}
Can somebody please, explain me what is aliasing and solution to this problem.
Thanks.
|
 |
Prabhjot Jassal
Greenhorn
Joined: Jul 19, 2010
Posts: 22
|
|
|
i don't think it would compile as you are trying to access, char c which is an instance variable in static method.
|
 |
Stephen Silva
Greenhorn
Joined: Jul 12, 2011
Posts: 18
|
|
Thanks for the reply.
It compiles with slight modifications to the code.
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("1: x.c "+x.c);
f(x);
System.out.println("2: x.c "+x.c);
}
But I want to know how to address the issue aliasing in this programme
|
 |
Hasanka Sandujith
Greenhorn
Joined: Sep 04, 2011
Posts: 1
|
|
This will give some idea... I think
Aliasing
|
 |
Stephen Silva
Greenhorn
Joined: Jul 12, 2011
Posts: 18
|
|
thanks
Need to know what the aliasing is in this programme and What does that really expect to do?
|
 |
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 4163
|
|
Suneth, we don't have too many rules around here, but we do ask that you BeForthrightWhenCrossPostingToOtherSites
http://www.java-forums.org/new-java/48162-aliasing-methods.html
|
luck, db
There are no new questions, but there may be new answers.
|
 |
Stephen Silva
Greenhorn
Joined: Jul 12, 2011
Posts: 18
|
|
Sorry, I don't know about that post.
But I am in need of having an idea about aliasing to answer this question.
I know it's your valuable time that you spend to answer these questions.
I always respect that.
Thanks.
|
 |
 |
|
|
subject: Aliasing
|
|
|