aspose file tools*
The moose likes Java in General and the fly likes a question about super command Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "a question about super command" Watch "a question about super command" New topic
Author

a question about super command

johny doe
Ranch Hand

Joined: Dec 07, 2007
Posts: 78
i got two classes one is extended from the other
there is also a super command inside the son class

the problem is when the debuger executes this super command

istead of continue from the super line

it starts going from the start of the son class

why is that??
why its not continuing from the super line???
Adam Schaible
Ranch Hand

Joined: Oct 04, 2007
Posts: 101
You'd have to post your code, or be much more descriptive to get a reasonable answer. Also, this should be in the beginner forum.
johny doe
Ranch Hand

Joined: Dec 07, 2007
Posts: 78
this is my code
and when the debugger finished making super command in class A
it goes to the start of B instead of
from the place of super command


public class A implements C
{
int d=17;
A(int d)
{
this.d=d;
}
A done()
{
System.out.println("I am done");
return this;
}

}


public class B extends A
{
int a=1;
int b=2;
public B(int a, int b)
{
this(a);
a=b;
}
public B(int b)
{
super(b);
a=b;
}
public A done()
{
System.out.println("finished");
return this;
}

public void print(int a, int b, int c)
{
System.out.println("a=" +a);
System.out.println("b=" +b);
System.out.println("c=" +c);
}
}


public interface C
{
public void print(int a, int b, int c);
}


public class MainClass
{

public static void main(String[] args)
{
B b=new B(7,11);
b.print(b.a,b.b,b.d);
A a= ((A)b).done();

}

}
johny doe
Ranch Hand

Joined: Dec 07, 2007
Posts: 78
i am confused about why its starting from the start of the class
and not from the super line??
Adam Schaible
Ranch Hand

Joined: Oct 04, 2007
Posts: 101
From JLS 8.3.2


8.3.2 Initialization of Fields
If a field declarator contains a variable initializer, then it has the semantics of an assignment (�15.26) to the declared variable, and:

If the declarator is for a class variable (that is, a static field), then the variable initializer is evaluated and the assignment performed exactly once, when the class is initialized (�12.4).
If the declarator is for an instance variable (that is, a field that is not static), then the variable initializer is evaluated and the assignment performed each time an instance of the class is created (�12.5).
The example:

class Point {
int x = 1, y = 5;
}
class Test {
public static void main(String[] args) {
Point p = new Point();
System.out.println(p.x + ", " + p.y);
}
}

produces the output:

1, 5

because the assignments to x and y occur whenever a new Point is created.
Variable initializers are also used in local variable declaration statements (�14.4), where the initializer is evaluated and the assignment performed each time the local variable declaration statement is executed.

It is a compile-time error if the evaluation of a variable initializer for a static field of a named class (or of an interface) can complete abruptly with a checked exception (�11.2).

It is compile-time error if an instance variable initializer of a named class can throw a checked exception unless that exception or one of its supertypes is explicitly declared in the throws clause of each constructor of its class and the class has at least one explicitly declared constructor. An instance variable initializer in an anonymous class (�15.9.5) can throw any exceptions.


Basically, when a class is initialized it initializes the fields if they have an assignment statement.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: a question about super command