Qual a diferença

2 respostas
faicoxim
class TestArrays
{
	public static void main (String args[])
	{
		int [] index = new int[4];
		index[0] = 1;
		index[1] = 3;
		index[2] = 0;
		index[3] = 2;
		
		String [] islands = new String[4];
		islands[0] = "Bermuda";
		islands[1] = "Fiji";
		islands[2] = "Azores";
		islands[3] = "Cozumel";
		
		int y = 0;
		int ref;
		
		while (y < 4)
		{
			ref = index[y];
			System.out.println("islands = ");
			System.out.println(islands[ref]);
			y = y + 1;
		}
	}
}
class Books
{
	String title;
	String author;
	
}
class BooksTestDrive
{
	public static void main (String args[])
	{
		Books[] myBooks = new Books[3];
		int x = 0;
		
		myBooks[0] = new Books(); //criar objetos books
		myBooks[1] = new Books();
		myBooks[2] = new Books();
		myBooks[0].title = "The Grapes of Java";
		myBooks[1].title = "The Java Gatsby";
		myBooks[2].title = "The Java CookBook";
		myBooks[0].author = "bob";
		myBooks[1].author = "sue";
		myBooks[2].author = "ian";
		
		while (x < 3)
		{
			System.out.println(myBooks[x].title);
			System.out.println("by");
			System.out.println(myBooks[x].author);
			x = x + 1;
		}
	}
}

Porque no segundo código tive que criar objetos Books 3 vezes ex:( myBooks[0] = new Books(); //criar objetos books) e no primeiro código não cria objetos

2 Respostas

T

int eh primitivo e string

http://www.guj.com.br/posts/list/51614.java

Marcio_Duran

No primeiro código, a classe TestArry ela tem variáveis de instância ? A classe TestArry propõe que nela você possa ter uma referência new ?, book é um objeto da outra classe, essa possui variáveis de instância ???; mas existe algo(atribuição) na classe TestArry que possa criar ou caracterizar um objeto.

[size=14]Click link abaixo, aqui tem explicações com mais detalhes!!![/size]

t+

:arrow: http://homepages.dcc.ufmg.br/~rodolfo/aedsi-2-08/cadeiadecaractere/cadeiadecaractere.html

Criado 2 de outubro de 2008
Ultima resposta 2 de out. de 2008
Respostas 2
Participantes 3