This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "First time using two classes!" Watch "First time using two classes!" New topic

First time using two classes!

Darragh Bourke

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);
} 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

Joined: Apr 12, 2008
Posts: 6
It compiled!!! Thank you Vishal Pandya.
I agree. Here's the link:
subject: First time using two classes!
It's not a secret anymore!