• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In other word, class B dont have method showVal()
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic