• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

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
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic