Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Object creation (newbeginner)

Status
Not open for further replies.

Xsi

Programmer
May 29, 2015
121
SE
Hello everyone,

I am very new to java,

I am trying to create a public class Person see below:


public class Person {

public Person(String name,String LastName)
{
System.out.println("Name:"+name);
System.out.println("LastName:"+LastName);
}

public static void main(String[]args)
{
// how do I alert name:"John" and LastName"Doe"

}
}

Thank you in advance
 
Hi

Given that the output statements are in the Person class's constructor, you only have to instantiate a Person object :
Java:
[b]public static[/b] [maroon]void[/maroon] [COLOR=orange]main[/color][teal]([/teal]String[teal][][/teal] args[teal])[/teal]
[teal]{[/teal]
    [b]new[/b] [COLOR=orange]Person[/color][teal]([/teal][i][green]"John"[/green][/i][teal],[/teal] [i][green]"Doe"[/green][/i][teal]);[/teal]
[teal]}[/teal]


Feherke.
feherke.github.io
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top