Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I'm learning java,currently a beginner.I was trying to use method parameters but this unexpected error has popped up

public class MyClass {
    public static void main(String[] args){

        //A method is a block of code which only runs when it is called
        sayHello(name:"Raj",age:20);

    }
    //method should be defined in the class

    public static void sayHello(String name, int age){
        System.out.println("Hello!");
    }
}

This code is returning folowwing errors for line 7:
‘)’ expected
‘;’ expected
‘not a statement’

I had expected the code to run as is should but I can’t seem to identify the error.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

in java there is no named- but positional-parameters only

so this is invalid:

sayHello(name:"Raj",age:20);

do instead:

sayHello("Raj", 20); 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading