• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help me with my compilation error!!

 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

class cout1{
int i =1;
void m(){
System.out.println("hi");
}
static class cin{
int i=2;
void method (){
System.out.println("cout.this.i ");
//System.out.println("this.i = "+ this.i);
}
}

}
class cout3 extends cout1.cin{
public static void main(String s[]){
cout3 t = new cout3();
t.prin();
}

void prin(){
abstract class loc{abstract void show1();}
class local extends loc{
void show1(){
System.out.println("hi");
}
}
new local().show1();
}


}
/*Superclass loc of local class local
(cout3. 1$local) not found.
class local extends loc{*/
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It compiles fine for me. Are you compiling using "-d ."? And does your class path include the current directory?
I put my javac and java commands in batch files, so that I can more easily see and change the values I use for each. The current flie contents are:
file cc.bat:
<code><pre>
c:\jdk1.3\bin\javac -classpath .;c:\jdk1.3 -d . Test.java
</pre></code>
file rr.bat:
<code><pre>
c:\jdk1.3\bin\java -classpath .;c:\jdk1.3 Test
</pre></code>
Obviously your paths may be different, and "Test" can be replaced with whatever class you're currently working with. But the nice thing is, once you've set this up, you can compile and run by typing just "cc" and then "rr". Or whatever names you want to give them. If you're using linux or something of course, you can translate this to something equivalent.
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jim. Any comments!
<code>
class cout1{
int i =1;
static class cin{
//////////////////////////////////////////////
abstract class loc{
abstract void show1();
}
//////////////////////////////////////////////
int i=2;
void method (){
System.out.println("cout.this.i ");
//System.out.println("this.i = "+ this.i);
}
}
void m(){
System.out.println("hi");
}
}
class cout3 extends cout1.cin{

//////////////////////////////////////////////
//abstract class loc{
//abstract void show1();
//}
//////////////////////////////////////////////
public static void main(String s[]){
cout3 t = new cout3();
t.prin();
}
void prin(){
/****************************************
* I also got the same error when I just compiled
* your program!!!
*
*
* This abstract local inner class 'loc' is not
* accessible by the other local inner class 'local'
* because ONLY LOCAL FINAL VARS AND FINAL METHOD ARGUMENTS
* are accessible to LOCAL INNER CLASSES.
* So the compiler sees 'class local extends loc', it
* knows that whatever it has got access locally
* are only FINAL vars, which it CAN NOT EXTEND
* ANYWAY, so it looks for any class in outer class
* 'cout3' . It could not find the class loc neither
* in class 'cout3' nor in cout3's superclass 'cout1.cin'
* So it complains...........
*
*Now put the 'abstract class loc' declaration
* either in class cout3 or in cout1.cin , it
* compiles without any problem as I have shown in this code
*
* It compiles and runs saying 'hi'
*****************************************/
abstract class loc{
abstract void show1();
}
class local extends loc{
void show1(){
System.out.println("hi");
}
}
new local().show1();
}
}
</code>
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. My first comment, which i should have made in my previous post, is this: everyone, when you're including code in your post, please indent the code properly and use the CODE tag to make it readable. This is described here (and is readily availible whenever you're composing a reply by clicking on the "UBB Code is ON" link just to the left of the composition area.) Read up on this stuff, and use it. It really helps. Thanks.
Now for the main question. It turns out, under further testing, that this code does compile using jdk 1.3, but does not when using jdk 1.2.2! I believe this is a bug in jdk 1.2.2 which has been fixed. It's true that there is a rule in the JLS (actually in the Nested Classes Specification here) saying that "if a local variable or parameter in one class is referred to by another (inner) class, it must be declared final". But this says nothing about accessing local classes, only local variables. So there should be no good reason that the class "local" should not be able to make use of the class definition of "loc", which is defined in the same scope as "local" (i.e. within the method prin()).
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Jim for the research!
I am using JDK1.2.2. So the possible reason I could find for the above problem was only that. Thank you.
For the sample program code I thought I should use the
<code>
</code> html tags and I used it . The code was intended properly when I wrote. But it didn't work properly. I am sorry for that.
Now I know what to do.
Thank you
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problem, this whole issue of how to use tags on this forum can be rather confusing. As you've seen, it's difficult to write about tags without having the darn things vanish on you because the system wants to interpret what you wrote, rather than simply print it.
I'm going to guess that you tried to say that you used the < code > HTML tag (note extra spaces to fool the system). You'd think that would work to save the indentation, but actually that just changes the font to look <code>like this</code>. To preserve indentation using HTML, you need the < pre > tag as well. Now, in this forum you can also use the [ code ] tag (not HTML but UBB code) to do both, with the added effect of putting a "code" label around your code, for better or worse. Whew!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic