Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interface

 
Neha Sawant
Ranch Hand
Posts: 204
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic