Reguri Praveen

Greenhorn
+ Follow
since Feb 19, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Reguri Praveen

Hi Friends,
I have cleared SCJP1.4 with 90%. The questions on Threads were really confusing. The questions on other topics were relatively easy. May be I have not worked on this topic. Still I could have done better.


Most of the time I was a silent participant. My special thanks to one and all for the helping me and replying my questions.

My sincere thanks to Maha, Ajith Kallambella,Jim Yingst for their beautiful explainations on http://www.javaranch.com/maha/Discussions/discussions.html

Also my thanks to marc weber.


Regards
Reguri
18 years ago
1. class Outer {
2. class Inner { }
3. }
4.
5. public class InheritInner extends Outer.Inner {
6. InheritInner () { }
7.
8. public static void main(String [ ] args) {
9. Outer o = new Outer( ) ;
10. InheritInner ii = new InheritInner( ) ;
11. }

The above code is from http://www.akgupta.com/Java/mock_exam.htm mock exam
Qno 38

It throws a error at compile time saying that
InheritInner.java:7: an enclosing instance that contains Outer.Inner is required
InheritInner () {


My question is can we inherit a inner class? If we can then why need the concept of inner class?

Thanks in advance for the help
Please help to understand the logic behind this program
class XY
{
static int x;
public static void main(String args[])
{
outer:
for (int i=0;i<5;i++)
{
if ( x==0 )
{
x++;
continue outer;
}
System.out.print(i);
}
}
}

The output of the above program is :1234

My query is that the int variable i in for loop is a local variable and should be reset to 0 when control goes out of the loop. Once the control is at the label outer, the value of the int i should be lost and i should be set to 0. But the value is retained by i.


Similarly with a few modifications where continue is replaced with break the below code generating the error while accessing the value of i outside the for loop

class XY
{
static int x;
public static void main(String args[])
{
loop:
for (int i=0;i<5;i++)
{
if ( x==0)
{
x++;
break loop;
}
System.out.println(i);
}
System.out.println(i);
}
}


Error is
XY.java:16: cannot resolve symbol
symbol : variable i
location: class XY
System.out.println(i);
^
1 error