• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Method help

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having trouble being able to set any values to firstName and lastName. I tried using the normal scanner scan and it wouldnt work. And for some reason i am not able to use Person in public static void main. Shouldnt I be able to type ?


My final code should work with this runner file
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You defined your class Person inside the main() method. While that's possible, it also means that you cannot use class Person anywhere outside the main() method.

Put class Person (lines 16-30 of your first code snippet) inside a separate source file named Person.java instead of inside the main() method.
 
Tyler Hudgens
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alright I have done so. But now even when i linked it in BlueJ it keeps giving me the error cannot find symbol - method Person()
SchoolClasses

Person Class

Am i calling it wrong?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Simply, there is no method Person() that takes zero arguments. There is a default constructor Person() that takes zero arguments -- because you didn't define any constructors.

Do you know the difference between the two? And the difference between calling a method and instantiating an object?

Henry
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And why does your Person class extend SchoolClasses ?
 
reply
    Bookmark Topic Watch Topic
  • New Topic