|
Constructor Help
Hi there, I'm new to Java. I'm taking an AP Java course in school and one of my assignments is to make a program that greets me by my name. However, I must declare the constructor explicitly. Here are the requirements:
1. Class name: MyGreetings2
2. Have two public string fields: lastName and firstName.
3. Make the constructor set lastName to your last name and firstName to your first name.
Here is the code that I've written:
public class MyGreetings2 {
public MyGreetings2() {
String firstName = Nick;
String lastName = Johnson;
}
public static void main(String[] args);
System.out.println("Hello, " + firstName + " " + lastName)
}
}
When I compile, I get two errors:
C:\JavaPrograms\MyGreetings2.java:10: <identifier> expected
System.out.println("Hello, " + firstName + " " + lastName)
^
C:\JavaPrograms\MyGreetings2.java:10: illegal start of type
System.out.println("Hello, " + firstName + " " + lastName)
Is there something huge I'm missing or doing wrong here? I've been trying to figure this out for hours. Oh, and I'm using JCreator for an IDE. Any help would be greatly appreciated.
Thanks!!
|