Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

generic doubt

 
sundar sankar
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

/*interface as line1
{
void ge();
}*/
class a1// implements as line 2
{
int a=12;
public void ge()
{
System.out.println("form the class a");
System.out.println(a);
}
}
class a2 extends a1
{
int a=120;
public void ge()
{
System.out.println("form the class b");
System.out.println(a);

}
}
class c <T>// extends a1>
{
T gen;
public c(T va)
{
this.gen=va;
}
public void set()
{
System.out.println(gen+" ," +gen.getClass());
gen.ge();
}
}
class d
{
public static void main(String ava[])
{
a1 ad=new a1();
c<a1> ad1=new c<a1>(ad);
ad1.set();
}
}

iN the above program if i uncomment the line1(interface) and line 2 i got compile time error as method gen.ge() not found in java.object.lang.
please help me in this regard
thanks in advance
sankar
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess is that when you uncommented those lines, you forgot to put the bound on the type parameter of c.

This code will compile.


[ June 26, 2007: Message edited by: Keith Lynn ]
 
sundar sankar
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Iam getting compile error with comment in line 1 and line 2
thanks
sankar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic