Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Whats wrong with this code ?

 
Ghazala Islam
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class chkconversion {
class abc {
int k=9;
}
abc a = new abc(),c ;
Object b = a;
c = (abc) b; //giving error

}
Its giving error on last line that
* identifier Expected
* cannot resolve symbol c
[ June 06, 2002: Message edited by: Ghazala Islam ]
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the problem is this line:
...
abc a = new abc(),c ;
...
this should be something like this:
 
Marcel de Jong
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This doesn't give any compile errors:
 
Ghazala Islam
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Marcel,
Your code worked,but please clear,whats the
differnece between
abc c;
c=(abc)b;
&
abc c = (abc)b;
why does it not identify c if its declare before?
[ June 07, 2002: Message edited by: Ghazala Islam ]
 
Brusk Baran
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There must not exist any difference between Compliler interpretations of these two:
abc c;
c=(abc)b;
&
abc c = (abc)b;

this is a BUG!!!
 
awais syed
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in java a class can declare static and non static memebers they can be variables, methods, blocks and classes and also interface(static by default). so any statement that has assignment may come on declaring variables like
class xyz
{
int a = amethod();
public int amethod(){
return 10;
}
}
so in your code if you write it using instance initialization block it will work perfectly
like
[QB]class chkconversion {
class abc {
int k=9;
}
abc a = new abc(),c ;
Object b = a;
{
c = (abc) b; //compile ok
}
}
[ June 09, 2002: Message edited by: awais syed ]
[ June 09, 2002: Message edited by: awais syed ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic