Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 428
  • Last Modified:

java error: can't find symbol

I have a problem.  I don't understand how to use a constructor with an instance class.  I created the math classes and set up a demo class but the specific stub doesn't work with factorial class and I get the error can't find the symbol factorial.  Are the classes formulated correctly and if not what do I need to do to have the factorial class recognized? I am new to java and trying to catch up in a class about it.  mathclass.java
0
tangocoder
Asked:
tangocoder
  • 5
1 Solution
 
zzynxSoftware engineerCommented:
Replace
factorial afact = new factorial(num);

Open in new window

by
factorial afact = MyMath.factorial(num);

Open in new window

0
 
zzynxSoftware engineerCommented:
>>  what do I need to do to have the factorial class recognized?
factorial is not a class. MyMath is a class (containing only static methods)
To call a static method of a class you write

<ClassName>.<method name>(<method parameters if any>)
0
 
tangocoderAuthor Commented:
Now the problem is that factorial in TestMyMath class is giving can't find symbol error.  How do I initialize factorial to be defined in this class?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
zzynxSoftware engineerCommented:
By importing your MyMath class, the way you imported the JOptionPane class by writing:
import javax.swing.JOptionPane;

Open in new window


So, you should write somehting like:

import <path of your MyMath class>.MyMath;

Open in new window

0
 
zzynxSoftware engineerCommented:
Normally each of your classes has as a first line something like:

package com.MyFirm.whatever;

If both your MyMath class and your TestMyMath class are in the same package (and have the same package line, that import is not needed since they "see" each other)

If the MyMath class is in another package, you have to tell your TestMyMath class in which package it has to look to find the MyMath class via that import instruction.

Some explanation about packages: http://www.tutorialspoint.com/java/java_packages.htm
0
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Can you post your updated code? And post each .java file separately and exactly as you have it.
0
 
zzynxSoftware engineerCommented:
Thanx 4 axxepting
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now