• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

First time using two classes!

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It compiled!!! Thank you Vishal Pandya.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic