wood burning stoves*
The moose likes Beginning Java and the fly likes First time using two classes! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "First time using two classes!" Watch "First time using two classes!" New topic
Author

First time using two classes!

Darragh Bourke
Greenhorn

Joined: Apr 12, 2008
Posts: 6
I am just a beginner with programming and it's my first time using two classes and it just won't compile can someone help please?

import javax.swing.JOptionPane;

class person{
String name;
int age;
public void person(String n, int a){

name = n;
age = a ;
}
public String getDetails(){
return name +" ("+age+")";
}
}
public class sortperson
{
public static void main(String[] args)
{
String m = JOptionPane.showInputDialog(null, "Enter a Name: ");
String s = JOptionPane.showInputDialog(null, "Enter an Age: ");
int g = Integer.parseInt(s);
person p = new person(m,g);
JOptionPane.showMessageDialog(null, "Your Person is" +p);
System.exit(0);
}
}
sortperson.java:22: cannot find symbol
symbol : constructor person(java.lang.String,int)
location: class person
person p = new person(m,g);
^
1 error
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Hey darragh,

You have declared a return type (void) to the constructor person. The rule for constructor is, constructor can't have any return type.Not even void.
Darragh Bourke
Greenhorn

Joined: Apr 12, 2008
Posts: 6
It compiled!!! Thank you Vishal Pandya.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: First time using two classes!
 
Similar Threads
Exception in thread "main" java.lang.NullPointerException
comparison
BufferedReader help
please help
dialog box with final info in it