• 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

a question about this code

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when i tried to understand a certain code
i got interface called Stack
and a stack class called StackAsArray

1.why are they creating a stack variable called
StackAsArray s = new StackAsArray();

Stack has no meening it just an interface
which inculdes all the method wich we need to create inside of
StackAsArray class.
???

2.when i tried to build this code from scratch
and i written the line
StringTokenizer t = new StringTokenizer(exp);
it sayed that there is no such type
why???

3.in my code i defined a stack and a char like this
StackAsArray st=new StackAsArray();
char ch;

when i tried to pop a member from a stack

ch=(char)st.pop();
it sayd
"cannot convert from object to char"

why ???
i did casting

[ January 01, 2008: Message edited by: johny doe ]
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by johny doe:
when i tried to understand a certain code
i got interface called Stack
and a stack class called StackAsArray

1.why are they creating a stack variable called
StackAsArray s = new StackAsArray();



Carefully look at the code. An instance of a class StacksArray has been created and NOT of interface Stack.


Stack has no meening it just an interface which inculdes all the method wich we need to create inside of StackAsArray class.
???



Yes. very true. You don't need to create but define the methods inside the StacksArray class provided if it implements the Stack interface.

Obviously, you don't need an object for an interface and you can't do so. The compiler makes sure the same.
[ January 01, 2008: Message edited by: Raghavan Muthu ]
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by johny doe:

2.when i tried to build this code from scratch
and i written the line
StringTokenizer t = new StringTokenizer(exp);
it sayed that there is no such type
why???



Many times you are told Johny Doe.

Kindly make use of separate threads per question. Carefully read this link.

Please stick to the rules. Also spend some time in listening to others who are helping you.
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


3.in my code i defined a stack and a char like this
StackAsArray st=new StackAsArray();
char ch;

when i tried to pop a member from a stack

ch=(char)st.pop();
it sayd
"cannot convert from object to char"

why ???
i did casting



Could you please post this in a new thread?
 
johny doe
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what do meen

"its defined as intance"

what does it meen??
for me when i am using a constructor

i am making



but here in this example



Stack is an interface
which meens nothing because i got no code.
and after the word "new" we dont get "Stack"
but "StackAsArray".
i cant understand that.

and how did they use StringTokenizer
because when i tried to wright as they do
it says that there is no such type
[ January 01, 2008: Message edited by: johny doe ]
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by johny doe:
and how did they use StringTokenizer
because when i tried to wright as they do
it says that there is no such type


Have you imported either java.util.StringTokenizer or java.util.*?
 
johny doe
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it worked thanks
reply
    Bookmark Topic Watch Topic
  • New Topic