File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interface

 
Neha Sawant
Ranch Hand
Posts: 204
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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;
}
}
 
Roopa Bagur
Ranch Hand
Posts: 267
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 204
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 267
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 204
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 204
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Roopa ,
sorry i got it.it was my mistake.
Sorry once again
thanks for ur help
Neha
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic