• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Aliasing

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This will give some idea... I think
Aliasing
 
Stephen Silva
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks

Need to know what the aliasing is in this programme and What does that really expect to do?
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Stephen Silva
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic