aspose file tools*
The moose likes Java in General and the fly likes Method help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Method help" Watch "Method help" New topic
Author

Method help

Tyler Hudgens
Greenhorn

Joined: Dec 09, 2013
Posts: 7
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

Joined: Aug 16, 2005
Posts: 14347
    
  22

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Tyler Hudgens
Greenhorn

Joined: Dec 09, 2013
Posts: 7
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
Sheriff

Joined: Sep 28, 2004
Posts: 18989
    
  40


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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Stuart A. Burkett
Ranch Hand

Joined: May 30, 2012
Posts: 679
And why does your Person class extend SchoolClasses ?
 
wood burning stoves
 
subject: Method help