• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Method help

 
Tyler Hudgens
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Henry Wong
author
Marshal
Pie
Posts: 21007
77
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And why does your Person class extend SchoolClasses ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic