aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "interface" Watch "interface" New topic
Author

interface

Neha Sawant
Ranch Hand

Joined: Oct 11, 2001
Posts: 204

hi,
why is this not compiling.
i am getting undefined variable I on the last line.
Can anyone tell me what am i missing

interface I{
}
class Super{
}
public class abcde extends Super implements I{

public static void main(String args[]){

Super s=(Super)I;
}
}


nss
Roopa Bagur
Ranch Hand

Joined: Nov 03, 2000
Posts: 267
You have to declare a variable of type Interface I.
Look at the following code.
interface I{
}
class Super{
}
public class abcde extends Super implements I{

public static void main(String args[]){
I i = null;
Super s=(Super)i;
}
}

Originally posted by Neha Sawant:

hi,
why is this not compiling.
i am getting undefined variable I on the last line.
Can anyone tell me what am i missing

interface I{
}
class Super{
}
public class abcde extends Super implements I{

public static void main(String args[]){

Super s=(Super)I;
}
}

Neha Sawant
Ranch Hand

Joined: Oct 11, 2001
Posts: 204
thanks Roopa,
But if i do not want to initialize it to null and check whether I can be casted to Super then how do i go about.
- Neha
Roopa Bagur
Ranch Hand

Joined: Nov 03, 2000
Posts: 267
In case you want the variable to have an proper value you could do.
I i = new abcde();
(An Interface type can be assigned a class that implements it)
Roopa.
Originally posted by Neha Sawant:
thanks Roopa,
But if i do not want to initialize it to null and check whether I can be casted to Super then how do i go about.
- Neha

Neha Sawant
Ranch Hand

Joined: Oct 11, 2001
Posts: 204
Hi Roopa,
i tried doing that way,i am getting the same error.
Did u compile the code or i am making some mistake
-
neha
Neha Sawant
Ranch Hand

Joined: Oct 11, 2001
Posts: 204
Hey Roopa ,
sorry i got it.it was my mistake.
Sorry once again
thanks for ur help
Neha
 
jQuery in Action, 2nd edition
 
subject: interface