+ 3

Can i create more than one object with same name for a class. For example , like the program in my link

https://code.sololearn.com/cCD1b3mOJ5hj/?ref=app

20th Dec 2017, 12:27 PM
bhavana goud
bhavana goud - avatar
8 Respuestas
+ 2
not sure what you mean but you can never create two variables/objects with the same name. (except in different scopes)
20th Dec 2017, 1:13 PM
Jeremy
Jeremy - avatar
+ 1
why dont you just click run and see for yourself?
20th Dec 2017, 12:36 PM
Jeremy
Jeremy - avatar
+ 1
now where are you using the same name?
20th Dec 2017, 1:37 PM
Jeremy
Jeremy - avatar
+ 1
@Jeremy. Sorry 😅. I forgot about the Scope of objects. and I was thinking that the objects with same name are used there . Actually. there in the push operation each time when it is getting called. object is getting created and getting destroyed.
20th Dec 2017, 2:09 PM
bhavana goud
bhavana goud - avatar
+ 1
@Rudolph flash. If they get destroyed then how can we access them again during push ?
20th Dec 2017, 2:10 PM
bhavana goud
bhavana goud - avatar
0
@ Jeremy. I've tested it 😅 it has shown me error ,but why still I asked this is. In java for stacks using linked lists objects with same name are created for every push operation then why isn't than an error ?
20th Dec 2017, 1:06 PM
bhavana goud
bhavana goud - avatar
0
@ Rudolph flash. In java for stacks using linked lists objects with same name are created for every push operation then why isn't that an error ? I have seen the code for stacks from Google. I didn't try it.But is it the same thing ?that in stack objects of Same name are getting created.
20th Dec 2017, 1:09 PM
bhavana goud
bhavana goud - avatar
0
@Rudolph Flash. Can you please this code ? public class LinkList { private Node first = null; public void push(int data) { Node n = new Node(data); n.next = first; first = n; } } public class LinkListStackDemo { public static void main(String[] args) { LinkList st = new LinkListStack(); st.push(50); st.push(70); st.push(190); } }
20th Dec 2017, 1:31 PM
bhavana goud
bhavana goud - avatar