• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

interface

 
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
}
}
 
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Roopa ,
sorry i got it.it was my mistake.
Sorry once again
thanks for ur help
Neha
 
Today you are you, that is turer than true. There is no one alive who is youer than you! - Seuss. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic