Andre Zhang

Greenhorn
+ Follow
since Aug 14, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Andre Zhang

Originally posted by Valentin Crettaz:
yes it is, but they are hidden instead


does HIDDEN mean that the static method cant be accessed by the subclass?
hi,all
here's the question
Which of these statements concerning nested classes are true?
Select all valid answers.
a. An instance of a top-level nested class has an inherent outer instance.
b. A top-level nested class can contain non-static member variables.
c. A top-level nested interface can contain non-static member variables.
d. A top-level nested interface has an inherent outer instance.
e. For each instance of the outer class, there can exist many instances of a non-static inner class.
Let's make the code simple first.
public class G124 extends Thread
{
G124 a = new G124();
public static void main(String[] args)
{
G124 a = new G124();
}
}
it will causes a hang-on at runtime because the unstoppable creation the a.
change this code a little more at the class declaration.
public class G124
{
G124 a = new G124();
public static void main(String[] args)
{
G124 a = new G124();
}
}
it causes a runtime error -- java.lang.StackOverflowError
my Question is: what's the difference between the two & why?
Now matter what s is, it will mod 32 first (s%=32) if the type of n is int & mod 64 (s%=64) if the type of n is long.
Sorry, I still dont get it. Can somebody show me some books for reference.

Originally posted by sonir shah:
I came across a question in the mock
It is as under :
class A {
A() {
System.out.println("Class A Constructor");
}
}
public class B extends A {
B() {
System.out.println("Class B Constructor");
}
public static void main(String args[]) {
B b = new B();
}
}
// the output here is "Class A Constructor followed by Class B Constructor //
again similar question i came across.It is as under :

class A {
A(double d) {
System.out.println("Printing the value of d is 10");
}
}
public class B extends A {
B() {
System.out.println("Class B Constructor");
}
public static void main(String args[]) {
B b = new B();
}
}
[a] Printing the value of d is 10 followed by Class B Constructor
[b] Printing the value of d is 10
[c] Compile time error
[d] Run time error
//The output here is Complile Time Error..
Can any one explain me the diffrence between the two??


Because in the 2nd example, Constructor B() invokes its superclass Constructor A() implicitly. But there's no A() in Class A. this causes a compile time error.
Thanks Guy & Marc.
it will cause a run time error when i use it. But i think it should be failed in compile time 'cause it's logically wrong.
And if i run the program below:
public class TestArray
{
public static void main(String[] args)
{
int[][] A = new int[1][0];
int[][] B = new int[0][0];
int[][] C = new int[0][1];
System.out.println(A);
System.out.println(B);
System.out.println(C);
}
}
I'll get the output:
[[I@273d3c
[[I@256a7c
[[I@720eeb
while i think it shoule be illegal, but it's working. why?
what's the mechanism of memory allocation to Array?
Andre
Hi,
that's because the constructor B(int w) invokes super() implicitly. & after u define A(int w) only, there'll be no constructor of A with no arguments. this causes a compile time error.
if u change the code a little, it will be OK.
class A{
int x = 0;
A (int w){
x = w;
}
}
class B extends A{
int x = 0;
B(int w){
super(w);
x = w +1;
}
}
when i define an array like this...
int ArrayTest[][] = new int[0][1];
it will not cause a compile-error
& if i run the program, it will return an address to ArrayTest
my question is: how does the VML allocate memory to ArrayTest?