Re: [java-list] Casting

2002-03-12 Por tôpico Luiz Reginaldo



Caro Hudson,

 Pode ser :

 "public static 
void main(String argv[])"

 "public static 
void main(String joazinho[])"

 "public static 
void main(String oqueeuquiser[])"

 etc 


 A única observação é que o 
nome do parâmetro deve ser um identificador válido em Java.

Um grande abraço,

 Luiz 
Reginaldo

  - Original Message - 
  From: 
  Hudson 
  Costa 
  To: [EMAIL PROTECTED] 
  Sent: Sunday, March 10, 2002 2:23 
PM
  Subject: Re: [java-list] Casting
  
  Nesta linha 
  "public static void main(String argv[])"
  deve ser String args[] e nao String 
  argv
  Ok!?
  
  Hudson 
  Costa
  
  
- Original Message - 
From: 
Eduardo de Britto Castro 
To: [EMAIL PROTECTED] 
Sent: Tuesday, March 05, 2002 4:34 
PM
Subject: [java-list] Casting

Alguém poderia me ajudar nesta questão? Estou 
enviando como anexo uma classe que faz a mesma coisa e não ocorre erro 
nenhum na linha 18.


Java Programmer Certification Mock Exam 
No 1 


Question 17)
What will happen if you attempt to compile and run the following code? 
class Base {}
class Sub extends Base {}
class Sub2 extends Base {}
public class CEx{
public static void main(String argv[]){
	Base b=new Base();
	Sub s=(Sub) b;
}
}

1) Compile and run without error 2) Compile time Exception 3) 
Runtime Exception 
Answer 17)
3) Runtime Exception 
Without the cast to sub you would get a 
compile time error. The cast tells the compiler that you really mean to do 
this and the actual type of b does not get resolved until runtime. Casting 
down the object hierarchy as the compiler cannot be sure what has been 
implemented in descendent classes. Casting up is not a problem because sub 
classes will have the features of the base classes. This can feel counter 
intuitive if you are aware that with primitives casting is allowed for 
widening operations (ie byte to int). 



-- LISTA SOUJAVA 
 http://www.soujava.org.br - 
Sociedade de Usuários Java da Sucesu-SP dúvidas mais comuns: 
http://www.soujava.org.br/faq.htmregras da lista: 
http://www.soujava.org.br/regras.htmhistorico: 
http://www.mail-archive.com/java-list%40soujava.org.brpara sair da 
lista: envie email para [EMAIL PROTECTED] 
-


Re: [java-list] Casting

2002-03-12 Por tôpico Anderson Corrêa

Nesta linha pode ser até "public static void main(String chacombolachas[])" 
isso não importaé um array como outro qualquer...












+--+


Anderson Magalhães Corrêa

Programador Java-Politec Informática 

 [EMAIL PROTECTED]

+--+
















From: "Hudson Costa" <[EMAIL PROTECTED]>
Reply-To: [EMAIL PROTECTED] 
To: <[EMAIL PROTECTED]>
Subject: Re: [java-list] Casting 
Date: Sun, 10 Mar 2002 14:23:28 -0300 
 
Nesta linha "public static void main(String argv[])" 
deve ser String args[] e nao String argv 
Ok!? 
 
Hudson Costa 
 
 
 - Original Message - 
 From: Eduardo de Britto Castro 
 To: [EMAIL PROTECTED] 
 Sent: Tuesday, March 05, 2002 4:34 PM 
 Subject: [java-list] Casting 
 
 
 Alguém poderia me ajudar nesta questão? Estou enviando como anexo uma classe que faz a mesma coisa e não ocorre erro nenhum na linha 18. 
 
 
 Java Programmer Certification Mock Exam No 1 
 Question 17) 
 What will happen if you attempt to compile and run the following code? 
 
class Base {} 
class Sub extends Base {} 
class Sub2 extends Base {} 
public class CEx{ 
 public static void main(String argv[]){ 
 Base b=new Base(); 
 Sub s=(Sub) b; 
 } 
} 
 
 1) Compile and run without error 
 2) Compile time Exception 
 3) Runtime Exception 
 
 
 Answer 17) 
 3) Runtime Exception 
 
 Without the cast to sub you would get a compile time error. The cast tells the compiler that you really mean to do this and the actual type of b does not get resolved until runtime. Casting down the object hierarchy as the compiler cannot be sure what has been implemented in descendent classes. Casting up is not a problem because sub classes will have the features of the base classes. This can feel counter intuitive if you are aware that with primitives casting is allowed for widening operations (ie byte to int). 
 
 
 
-- 
 
 
 -- LISTA SOUJAVA  
 http://www.soujava.org.br - Sociedade de Usuários Java da Sucesu-SP 
 dúvidas mais comuns: http://www.soujava.org.br/faq.htm 
 regras da lista: http://www.soujava.org.br/regras.htm 
 historico: http://www.mail-archive.com/java-list%40soujava.org.br 
 para sair da lista: envie email para [EMAIL PROTECTED] 
 - 
Converse com amigos on-line, experimente o MSN Messenger: http://messenger.msn.com.br

-- LISTA SOUJAVA  
http://www.soujava.org.br  -  Sociedade de Usuários Java da Sucesu-SP 
dúvidas mais comuns: http://www.soujava.org.br/faq.htm
regras da lista: http://www.soujava.org.br/regras.htm
historico: http://www.mail-archive.com/java-list%40soujava.org.br
para sair da lista: envie email para [EMAIL PROTECTED] 
-



Re: [java-list] Casting

2002-03-12 Por tôpico Lincolm Ferreira de Aguiar



O problema é que Sub é filha de 
Base, o erro ocorre porque o compilador não consegue fazer a conversão para um 
nível acima na hieraquia. Serial algo assim. A classe-filha pode ser usada onde 
a classe-pai é usada. A classe-filha apenas tem especializações a mais que a 
distinguem da classe-pai, mas ainda tem as características da classe pai. Já a 
utilização da classe-pai onde é esperada a classe-filha dá problemas pois a 
implementação é diferente.

Espero ter ajudado,

Lincolm Ferreira de 
AguiarWebMaster - QueroProgramar[EMAIL PROTECTED]

www.geocities.com/lincolmf

- Original Message - 

  From: 
  Hudson 
  Costa 
  To: [EMAIL PROTECTED] 
  Sent: Sunday, March 10, 2002 2:23 
PM
  Subject: Re: [java-list] Casting
  
  Nesta linha 
  "public static void main(String argv[])"
  deve ser String args[] e nao String 
  argv
  Ok!?
  
  Hudson 
  Costa
  
  
- Original Message - 
From: 
Eduardo de Britto Castro 

To: [EMAIL PROTECTED] 
Sent: Tuesday, March 05, 2002 4:34 
PM
Subject: [java-list] Casting

Alguém poderia me ajudar nesta questão? Estou 
enviando como anexo uma classe que faz a mesma coisa e não ocorre erro 
nenhum na linha 18.


Java Programmer Certification Mock Exam 
No 1 


Question 17)
What will happen if you attempt to compile and run the following code? 
class Base {}
class Sub extends Base {}
class Sub2 extends Base {}
public class CEx{
public static void main(String argv[]){
	Base b=new Base();
	Sub s=(Sub) b;
}
}

1) Compile and run without error 2) Compile time Exception 3) 
Runtime Exception 
Answer 17)
3) Runtime Exception 
Without the cast to sub you would get a 
compile time error. The cast tells the compiler that you really mean to do 
this and the actual type of b does not get resolved until runtime. Casting 
down the object hierarchy as the compiler cannot be sure what has been 
implemented in descendent classes. Casting up is not a problem because sub 
classes will have the features of the base classes. This can feel counter 
intuitive if you are aware that with primitives casting is allowed for 
widening operations (ie byte to int). 



-- LISTA SOUJAVA 
 http://www.soujava.org.br - 
Sociedade de Usuários Java da Sucesu-SP dúvidas mais comuns: 
http://www.soujava.org.br/faq.htmregras da lista: 
http://www.soujava.org.br/regras.htmhistorico: 
http://www.mail-archive.com/java-list%40soujava.org.brpara sair da 
lista: envie email para [EMAIL PROTECTED] 
-


Re: [java-list] Casting

2002-03-12 Por tôpico Helder da Rocha

 - Original Message -
 From: Hudson Costa
 To: [EMAIL PROTECTED]
 Sent: Sunday, March 10, 2002 2:23 PM
 Subject: Re: [java-list] Casting

 Nesta linha public static void main(String argv[])
 deve ser String args[] e nao String argv
 Ok!?

O nome não precisa ser args!

 public static void main(String argv[]) está certo!
public static void main(String argumentos[]) também!
static public void main(String[] x) está certo.
static public void main(String[] eraUmaVezUmaVariavelGigante) também!

O importante é que main seja public, static, void e tenha um argumento do
tipo vetor de strings. Só isto!


-- LISTA SOUJAVA  
http://www.soujava.org.br  -  Sociedade de Usuários Java da Sucesu-SP 
dúvidas mais comuns: http://www.soujava.org.br/faq.htm
regras da lista: http://www.soujava.org.br/regras.htm
historico: http://www.mail-archive.com/java-list%40soujava.org.br
para sair da lista: envie email para [EMAIL PROTECTED] 
-




Re: [java-list] Casting

2002-03-11 Por tôpico Fabricio



Eduardo 


  
 Nao é a mesma coisa não, pois a variavel ob vai ser um 
TextField. 
(...) Object ob = 
(Object) e.getComponent(); if (ob instanceof 
TextField) 
{ TextField tc = (TextField) 
ob; char c = 
e.getKeyChar(); // Somente 
caracteres imprimiveis serao 
destruidos if ((c = 32 
 c = 126)  (!e.isActionKey())) // ActionKey=teclas 
especiais 
if (tc.getText().length() = 
tc.getColumns()) 
e.consume(); }(...)

Reescrevendo a classe para ela se tornar igual a 
seu exemlpo...

class Base {}class Sub extends Base {}class Sub2 
extends Base {}public class CEx{ public static void 
main(String argv[]){	Base b=new Sub(); //Aqui esta a 
diferenca, b vai ser uma intancia de Sub e na questao b era uma instancia 
de Base	Sub s=(Sub) b; 
}}

  - Original Message - 
  From: 
  Eduardo de Britto Castro 
  To: [EMAIL PROTECTED] 
  Sent: Tuesday, March 05, 2002 4:34 
  PM
  Subject: [java-list] Casting
  
  Alguém poderia me ajudar nesta questão? Estou 
  enviando como anexo uma classe que faz a mesma coisa e não ocorre erro nenhum 
  na linha 18.
  
  
  Java Programmer Certification Mock Exam 
  No 1 
  
  
  Question 17)
  What will happen if you attempt to compile and run the following code? class Base {}
class Sub extends Base {}
class Sub2 extends Base {}
public class CEx{
public static void main(String argv[]){
	Base b=new Base();
	Sub s=(Sub) b;
}
}

  1) Compile and run without error 2) Compile time Exception 3) 
  Runtime Exception 
  Answer 17)
  3) Runtime Exception 
  Without the cast to sub you would get a compile 
  time error. The cast tells the compiler that you really mean to do this and 
  the actual type of b does not get resolved until runtime. Casting down the 
  object hierarchy as the compiler cannot be sure what has been implemented in 
  descendent classes. Casting up is not a problem because sub classes will have 
  the features of the base classes. This can feel counter intuitive if you are 
  aware that with primitives casting is allowed for widening operations (ie byte 
  to int). 
  
  

  -- LISTA SOUJAVA 
   http://www.soujava.org.br - 
  Sociedade de Usuários Java da Sucesu-SP dúvidas mais comuns: 
  http://www.soujava.org.br/faq.htmregras da lista: 
  http://www.soujava.org.br/regras.htmhistorico: 
  http://www.mail-archive.com/java-list%40soujava.org.brpara sair da lista: 
  envie email para [EMAIL PROTECTED] 
  -


Re: [java-list] Casting

2002-03-11 Por tôpico Hudson Costa



Nesta linha 
"public static void main(String argv[])"
deve ser String args[] e nao String 
argv
Ok!?

Hudson Costa


  - Original Message - 
  From: 
  Eduardo de Britto Castro 
  To: [EMAIL PROTECTED] 
  Sent: Tuesday, March 05, 2002 4:34 
  PM
  Subject: [java-list] Casting
  
  Alguém poderia me ajudar nesta questão? Estou 
  enviando como anexo uma classe que faz a mesma coisa e não ocorre erro nenhum 
  na linha 18.
  
  
  Java Programmer Certification Mock Exam 
  No 1 
  
  
  Question 17)
  What will happen if you attempt to compile and run the following code? class Base {}
class Sub extends Base {}
class Sub2 extends Base {}
public class CEx{
public static void main(String argv[]){
	Base b=new Base();
	Sub s=(Sub) b;
}
}

  1) Compile and run without error 2) Compile time Exception 3) 
  Runtime Exception 
  Answer 17)
  3) Runtime Exception 
  Without the cast to sub you would get a compile 
  time error. The cast tells the compiler that you really mean to do this and 
  the actual type of b does not get resolved until runtime. Casting down the 
  object hierarchy as the compiler cannot be sure what has been implemented in 
  descendent classes. Casting up is not a problem because sub classes will have 
  the features of the base classes. This can feel counter intuitive if you are 
  aware that with primitives casting is allowed for widening operations (ie byte 
  to int). 
  
  

  -- LISTA SOUJAVA 
   http://www.soujava.org.br - 
  Sociedade de Usuários Java da Sucesu-SP dúvidas mais comuns: 
  http://www.soujava.org.br/faq.htmregras da lista: 
  http://www.soujava.org.br/regras.htmhistorico: 
  http://www.mail-archive.com/java-list%40soujava.org.brpara sair da lista: 
  envie email para [EMAIL PROTECTED] 
  -