General Java Questions I
implement one or more interfaces. Interfaces are Java s way to support multiple
inheritance.
 Q: There are two interfaces which have a common methods action() in them and
class implements both of them...
There are two interfaces which have a common methods action() in them and class
implements both of them, override them and then in a test class simply call action. 
Which will be called?
And next: is there any way of resolving this conflict like in c++ we can
first::action();
second::action();
is something same is there in java?
Answer: 
1. Neither. The compiler will refuse to compile Hello because it has two methods with
the same name and parameter list.
2. In Java, one would usually deal with this sort of situation by implementing the
interfaces in Hello s inner classes, rather than the Hello itself. You can have two inner
classes, each implementing one of the interfaces, and each with an action method
that just calls a uniquely named method in the surrounding Hello object.
  
Patricia
 Does anyone know how could I get the size of an Enumeration object? The API
for Enumeration only contains getNext() and next().
Answer 1: You can t. Theoretically, some classes that implement Enumeration may
also provide some way to get a size, but you d have to know about the more specific
run time type and cast to it... and none of the standard java.util Collections classes
nor Vector or such provide these methods in their Enumeration implementations.
Answer2:  
you can make your own class like this:
import java.util.*;
public class MyEnumeration{
   int size;
   int index = 0;
   Enumeration e;
   public MyEnumeration(Vector v){
      size = v.size();
      e = v.elements();
      index = 0;
   }
   public boolean hasMoreElements(){
      return e.hasMoreElements();
   }
file:///F|/a_jsite/350_tips/general_java I.htm (8 of 33) [2001 07 08 11:24:51]






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java web hosting

 

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved