Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Wayne Crawford   on Oct 23 In Java Category.

  
Question Answered By: Lily Brown   on Oct 23

Try code below :

public class  Passenger
{
String name;
String address;
int age;

public Passenger(String n, String add, int  a)
{
name = n;
address = add;
age = a;
}


public int getAge()
{
return age;
}

public String getAddress()
{
return address;
}
public String getName()
{
return name;
}

public void  PrintList()
{
/*Passenger p1 = new Passenger();
p1.printList();*/

System.out.println("My name  is" + name);
System.out.println("My address  is" + address);
System.out.println("My age  is" + age);
}

public static  void main(String[] args)
{

/*Traveller[] travellerlist = new Traveller[3];*/
Passenger[] travellerlist = new Passenger[3];

travellerlist[0] = new Passenger("Jim","London",48);
travellerlist[1] = new Passenger("Sue","Manchester",22);
travellerlist[2] = new Passenger("Matt","Bristol",31);


for (int i =0; i<3; i++)
{
travellerlist[i].PrintList();
System.out.println ("==========================");
}
}
}

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on array display class Or get search suggestion and latest updates.


Tagged: