Caros,
não entendi porque tem que ter o cast de String
para chamar o metodo baixo já que a classe que estou
instanciando não é Second
public class First {
public Object method1(){
System.out.println("Calling super class method");
return new String("Base");
}
}
public class Second extends First {
public String method1(){
System.out.println("Calling sub class method");
return new String("Derived");
}
}
public class TestFirstSecond {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
First o = new Second();
String s= (String)o.method1();
System.out.println(s);
}
}
No codigo abaixo não compila porque o metodo é somente
da classe Ex56 …
Qual seria a regra pra saber qdo compila :
- quando o metodo está na duas classes
- compilaria se colocase Ex56 b = new EX56()
gostaria de fazer um roteiro pra amarrar esse tipo de situação???
class Base56{}
public class Ex56 extends Base56{
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Base56 b = new Ex56();
b.getDerived();
}
public void getDerived(){
System.out.println("In Derived");
}
}
uma duvida como faço pra ler o conteudo do TreeMap
conforme exemplo abaixo :
class X implements Comparable{
String name;
public String toString(){
System.out.println(name);
return name;
}
X(String name){
this.name=name;
}
public int compareTo(Object o) {
// TODO Auto-generated method stub
X x=(X) o;
return name.compareTo(x.name);
}
}
public class Ex57 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
TreeMap <X,Integer> tree = new TreeMap <X,Integer>();
tree.put(new X("TOm"), 1);
tree.put(new X("Huck"), 2);
tree.put(new X("Jack"), 2);
}
}
Duvida sobre thread por que printa de 1 a 20
já que a variavel cont não é estatica …???
não entendi …
abs
class A58 extends Thread{
Ex58 demo;
public A58 (Ex58 td){
demo=td;
}
public void run (){
demo.doSomething();
}
}
public class Ex58 {
private int count =1;
public synchronized void doSomething(){
for(int i=0;i<10;i++){
System.out.println(count++);
}
}
-----------------------------------
public static void main(String[] args) {
// TODO Auto-generated method stub
Ex58 demo = new Ex58();
Thread a1 = new A58(demo);
Thread a2 = new A58(demo);
a1.start();
a2.start();
}
}
[/code]
Duvida o que responder :
Given the following , wich of the given choices are valid ways of referring to MyClass from a class outside the
package mypackage.yourpackage ?
package mypackage.yourpackage;
public class MyClass{
//class definition
}
select 2 any options:
A) use import mypackage .* and refer to the class as yourpackage.MyClass
b) refer to the class as MyClass
c) refer to the class as mypackage .yourpackage.MyClass
d) use import yourpackage.* and refer to the class as MyClass
e) use import mypackage.yourpackage and refer to the class as MyClass
Outra Duvida sobre Externalizable ???
Which of the following statements about the Externalizable interface are true ???
select any 2 options :
a) The Externalizable interface is to be implemented by classes wich need complete control over serialization.
b) The Externalizable interface defines the writeObject() and readObject() methods.
c) The Externalizable interface does not define any method.
d) The Externalizable interface extends the Serializable interface.
duvida por que da erro o que fazer pra não dar erro ???
Exception in thread "main" java.text.ParseException: Unparseable date: "April 19,2005"
at java.text.DateFormat.parse(Unknown Source)
at br.com.cert.WhizLabs2.Ex72.main(Ex72.java:18)
public static void main(String[] args) throws ParseException {
// TODO Auto-generated method stub
String str="April 19,2005";
Date date = DateFormat.getDateInstance(DateFormat.LONG, Locale.US).parse(str);
System.out.println(date);
}