Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes Whats  wrong with this code ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Whats  wrong with this code ?" Watch "Whats  wrong with this code ?" New topic
Author

Whats wrong with this code ?

Ghazala Islam
Ranch Hand

Joined: Nov 22, 2000
Posts: 73
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

Joined: May 02, 2002
Posts: 196
I think the problem is this line:
...
abc a = new abc(),c ;
...
this should be something like this:
Marcel de Jong
Ranch Hand

Joined: May 27, 2002
Posts: 54
This doesn't give any compile errors:
Ghazala Islam
Ranch Hand

Joined: Nov 22, 2000
Posts: 73
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

Joined: Nov 15, 2001
Posts: 132
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

Joined: Mar 17, 2002
Posts: 7
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 ]

awais
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Whats wrong with this code ?