I’m new to programming, I’m sorry if this is a silly mistake, but I keep getting this error "CompanyAddress.java:11: error: cannot find symbol System.out.println(testObject.getName(CompanyName));" I don’t know what I’m doing wrong.
The main.
import java.util.Scanner;
public class CompanyAddress
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
test testObject = new test();
System.out.println("Enter name: ");
String input = scan.nextLine();
testObject.getName(input);
System.out.println(testObject.getName(CompanyName));
}
}
my test.java
import java.util.Scanner;
public class test
{
String Name;
public String getName(String CompanyName)
{
Name = CompanyName;
return Name;
}
}
First of all you need to declare your variable
companyName, before passing it to your method.Secondly, your method: –
Seems strange to me. You are using the same method as
getter and setter.You should have
separate setter and getter: –And invoke them separately.
Just a suggestion: –
Follow Java Naming Convention. Field names and method names should start with lowercase alphabet.