Q | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Q

How can I write a java program that will declare two string variables for student names containing first name and last name? Like this: String 1: Jack Wilson String 2: Dean Copper Result» String 1: Jack Copper String 2: Dean Wilson

6th Oct 2018, 10:53 PM
blackhole
blackhole - avatar
2 Answers
0
You can doit like this: public static void main (String[]args) { Student s1 = new Student("Jack","Copper"); Student s2 = new Student("Dean","Wilson"); s1.display(); s2.display(); } class Student { String firstName; String lastName; static int count = 1; Student (String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; } void display(){ System.out.println("String "+(count++)+": "+firstName+" "+lastName); } }
7th Oct 2018, 12:09 AM
JavaBobbo
JavaBobbo - avatar
7th Oct 2018, 2:02 AM
ifl
ifl - avatar