'cannot find symbol in java method
cal.java
package calculator;
class Cal
{
public int add(int num1,int num2)
{
return num1+num2;
}
public int mul(int num1,int num2)
{
return num1*num2;
}
public int sub(int num1,int num2)
{
return num1-num2;
}
public int div(int num1,int num2)
{
return num1/num2;
}
}
Final.java
import calculator.*;
import java.util.*;
public class Final
{
public static void main(String[] args)
{
Scanner in= new Scanner(System.in);
System.out.println("What operation would you like to perform? press 1 for add \n press 2 for sub \n press 3 for mul \n press 4 for divide\n");
Integer s=in.nextInt();
System.out.println("What is the first number?");
Integer n1=in.nextInt();
System.out.println("What is the second number you want to enter?");
Integer n2=in.nextInt();
Cal obj=new Cal();
switch(s)
{
case 1:
System.out.println(obj.add(n1+n2));
break;
case 2:
System.out.println(obj.sub(n1-n2));
break;
case 3:
System.out.println(obj.mul(n1*n2));
break;
case 4:
System.out.println(obj.div(n1/n2));
break;
}
}
}
I am trying to make a calculator using java packages and i keep getting these error
**calculator\\Final.java:14: error: cannot find symbol**
Cal obj=new Cal();
^
symbol: class Cal
location: class Final
calculator\\Final.java:14: error: cannot find symbol
Cal obj=new Cal();
^
symbol: class Cal
location: class Final
2 errors
Solution 1:[1]
class Cal has no visibility modifier (public, private, or protected), so it's defaulting to the seldom-used package-private visibility, which means it can only be seen in the current package and nowhere else. Declare it as
public class Cal { ... }
and you'll be able to see it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Silvio Mayolo |
