Connecting Tech Pros Worldwide Forums | Help | Site Map

Class Ambiguity problem.

dmjpro's Avatar
Lives Here
 
Join Date: Jan 2007
Location: India (West-Bengal)
Posts: 2,451
#1: May 18 '09
here is my code ...

Expand|Select|Wrap|Line Numbers
  1. import org.iitkan.*;
  2. import org.iitkgp.*;
  3.  
  4. public class AnotherTest {
  5.     public static void main(String a[]){
  6.         System.out.println("Debasis ...!!!!");
  7.         Test t = new Test();
  8.     }
  9. }
  10.  
The Test class exists in three packages .. org.iitkan, org.iitkgp and the default package. If i run this program then it runs well. How a class gets looked into the packages?
Here what's happening, first compiler look into the default package if not then ambiguity error flashed(if a class found in two imported different packages)? ;)

Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: May 18 '09

re: Class Ambiguity problem.


Are you saying you compiled and run the code or are you asking whether the code compiles or not?
dmjpro's Avatar
Lives Here
 
Join Date: Jan 2007
Location: India (West-Bengal)
Posts: 2,451
#3: May 18 '09

re: Class Ambiguity problem.


No no ... I am just asking what's the way to find out a class during compilation?
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#4: May 18 '09

re: Class Ambiguity problem.


I really can't make sense of the question.
If you want to know whether the code compiles or not, then just try it and see what will happen.
dmjpro's Avatar
Lives Here
 
Join Date: Jan 2007
Location: India (West-Bengal)
Posts: 2,451
#5: May 18 '09

re: Class Ambiguity problem.


Quote:

Originally Posted by r035198x View Post

I really can't make sense of the question.
If you want to know whether the code compiles or not, then just try it and see what will happen.

No no ..means ...
I compiled the code and ran it ;)
But i wanted to know the way of looking for a class.
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#6: May 18 '09

re: Class Ambiguity problem.


Quote:

Originally Posted by dmjpro View Post

No no ... I am just asking what's the way to find out a class during compilation?

A class is visible if it is an element of the class (to be compiled) from the same package or, if it has been made visible explicitly by an import statement. If more than one class with the same simple name is visible the simple class name is ambiguous and the compiler emits an error message. Read the JLS for a more detailed description.

kind regards,

Jos
dmjpro's Avatar
Lives Here
 
Join Date: Jan 2007
Location: India (West-Bengal)
Posts: 2,451
#7: May 19 '09

re: Class Ambiguity problem.


So i looked at the contents of JLS 3rd edition, but i could not find it out.
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#8: May 19 '09

re: Class Ambiguity problem.


Quote:

Originally Posted by dmjpro View Post

So i looked at the contents of JLS 3rd edition, but i could not find it out.

Well, that's easy then: give up, don't read the JLS and take my terse explanation for granted. The JLS is not a novel, i.e. you can't just 'look at the contents' and understand what it's all about; it takes reading and understanding. That's how language definitions are written.

kind regards,

Jos
dmjpro's Avatar
Lives Here
 
Join Date: Jan 2007
Location: India (West-Bengal)
Posts: 2,451
#9: May 19 '09

re: Class Ambiguity problem.


:) actually to read out the whole JLS .... oops !
That's what (patience) i lack ;)
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#10: May 19 '09

re: Class Ambiguity problem.


Quote:

Originally Posted by dmjpro View Post

:) actually to read out the whole JLS .... oops !
That's what (patience) i lack ;)

Well, you'd better give it a try, it is worth it; reading the JLS is not like browsing, skimming through something, copy and paste a few examples and have some half understood code up and running after some hacking.

A JLS is the definition of a language and it has to be exact in its wordings; it was (most likely) written by some language lawyers. Read it as such. Believe me, the JLS reads like a simple novel compared to the ANSI/ISO texts for the C OR C++ programming languages.

kind regards,

Jos
dmjpro's Avatar
Lives Here
 
Join Date: Jan 2007
Location: India (West-Bengal)
Posts: 2,451
#11: May 20 '09

re: Class Ambiguity problem.


Well .. impressive! ;)
But at the beginning there are some topics which is related to Automata Theory.
So from where i should start of?
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#12: May 20 '09

re: Class Ambiguity problem.


Quote:

Originally Posted by dmjpro View Post

Well .. impressive! ;)
But at the beginning there are some topics which is related to Automata Theory.
So from where i should start of?

They talk about grammars: the lexical grammar that defines the sequence of characters that make up valid tokens and the syntactical grammar that defines the syntactically valid sequences of tokens that make up valid program fragments. If grammars are not your cup of tea feel free to skip those sections.

kind regards,

Jos
Reply