When learning Java , some difficulties have arisen.
Idea
Create a pet that will just say that he wants the most primitive way.
Code:
Main class
Public Class Progs {
Public Static Void Main (String [] Args) {
PET MYPET = NEW PET ();
Mypeet.says ();
}
}
Side
Public Class Pet {
String [] All_says = {"I want to eat", "I want to drink", "everything is excellent"};
Public String Says (STRING NAMEPET, INT NEEDPET) {
String ND;
ifpet == 1) {
nd = all_says [1];
}
ELSE {
ifpet == 2) {
nd = all_says [2];
}
ELSE {
nd = all_says [3];
}
}
System.Out.printLN (namepet + ":" + Nd);
}
}
Public Class Fish {
String Name = "Karlson";
INT NEED = 1;
PET MYPET = NEW PET ();
Mypeet.says (Name, Need);
}
Error:
Compiler eclipse gives out such an error:
Exception in Thread “Main” java.lang.error: UnreSolved Compiltion Problem:
The Method Says (String, Int) in the Type Pet Is Not Applicable for the Arguments ()
at progs.main (progs.java:nd)
And yes, I know English and it says that types are not applicable for arguments. But I do not understand what is wrong?
Answer 1, Authority 100%
I’m certainly not strong in a stupip, but I think that Topicstarter should be removed hard – hard in the head that Java has a language that rigidly controls the number of parameters of the function / method and not only by the way the number of parameters, but also the type of elimination of the exception (if there is Such) and the type of return value. All this in the aggregate is called the method signature.
Now returning to the question. As you already correctly answered the compiler swearing on the mismatch of declared types to call it.
Signature of your method:
Public String Pet.says (String Namepet, Int Needpet)
And you try to call it like:
pet.says ();
Accordingly, the compiler is trying to find in the class Pet
method SAYS ()
without parameters and naturally does not find it there and from there and swears.
Answer 2, Authority 50%
The compiler swears on mypet.says (); In Public Static Void Main
There must be two parameters like String and Int