• Post Reply Bookmark Topic Watch Topic
  • New Topic

e below program is throwing error at compile time --- showVal(int a) can not applied to ()  RSS feed

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class A
{
static int k=10;

A getvalue(int a)
{ A ob = new A();
ob.k=a;
return ob;
}

}

class B
{

static A showVal(int a)
{
A ob = new A();
ob.k=50;

return ob;
}


}

class obRet
{
public static void main(String args[])
{
A ob1=new A();
ob1=new B().showVal();
System.out.println("k="+ob1.k);
}
}
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use the code button.

Look at how you have declared the showVal method and how many parameters it takes. Now look at how many arguments you are passing.
 
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your showVal() method takes in a parameter, which you do not pass in.

Hunter
 
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In other word, class B dont have method showVal()
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. class B does have a showVal() method it just takes a parameter that he is not passing in.

Hunter
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hunter McMillen wrote:No. class B does have a showVal() method it just takes a parameter that he is not passing in.


that is what I told. showVal() and showVal(int) both are different.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know this looks like splitting hairs, but the compiler looks for method signatures, which means the identifier of the method and the types of its parameters. So I would agree with Seetharaman Venkatasamy that you don't have a showVal() method, only showVal(int).
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with both of you that the method signatures are not the same. In my previous post I was referring by name, not signature.

Hunter
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!