Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
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
Forum:
Beginning Java
mutator method
SrinivasaRao Swarna
Greenhorn
Posts: 20
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi friends,
I have doubt with instantmethods
class person { private String name; private int age; person(String name,int age) { this.name=name; this.age=age; } void display() { System.out.println("Name="+name); System.out.println("age ="+age); } Object modify(Person obj) { obj.name="Laxmi"; } } class Demo { public static void main(String args[]) { Person p1=new Person("Rajesh",20); p1.display(); //------------------------- Person p2=p.modify(p1); //-------------------------- p1.diplay(); } }
in this program having erro in main method at dotted line please me
Thanks&Regards
Srinivas
[ June 03, 2008: Message edited by: Campbell Ritchie ]
Vikas Kapoor
Ranch Hand
Posts: 1374
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello Sri,
Always
copy and paste
your code from original location. You have made many mistakes while rewriting in this post.
The potential error that i could see is you haven't type cast from Object to person class.
person p2=(person) p1.modify(p1);
Is this the actual problem?
Campbell Ritchie
Marshal
Posts: 79179
377
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Vishal Pandya is correct about copy and paste; your modify method returns an Object which needs to be cast to person.
And always use code tags round quoted code; I have added them so you can see how much easier the code is to read.
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
HFJ doubt
Sort Arraylist by passing runtime parameter
passing Obj reference to the method
Comparator
More...