• Post Reply Bookmark Topic Watch Topic
  • New Topic

Annonymous class  RSS feed

 
mandeepsangwan kumar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
{
String fun();
}
class Demo implements p
{
public static void main(String arr[])
{
p x=new p(){
public String fun()
{
return "hello";
}

public String fun1()
{
return "hello";
}
};
System.out.println(x.fun());
System.out.println(x.fun1());
}

}


Why its giving error that can not find method fun1()
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mandeepsangwan kumar wrote:Why its giving error that can not find method fun1()

I have absolutely no idea, because what you've posted doesn't compile.

Also:
1. What error does it give? The EXACT error please.
2. Please UseCodeTags (←click).

Winston
 
mandeepsangwan kumar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can not found symbol : method fun1()
 
Paul Murray-Cbr
Greenhorn
Posts: 12
Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The variable x is of type p, and fun1() is not part of the definition of class p. Sure - as a matter of fact the particular object you have assigned to x does have an (anonymous) class that does have the method fun1(), but that's beside the point. You can also assign to x an object that doesn't contain fun1() - and there where would you be at runtime?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!