Members of a class are private by deafult. The following code doesn't work.
#include<iostream.h>
class Test
{
int x;
};
void main()
{ Test test = new Test();
test.x=10;
}
However the same code works in Java?
class Test {
int x=5;
}
public class MyClass{
public static void main(String args[]) {
Test test = new Test();
System.out.println(test.x);
}
}
According to me it should not work.. since int x is private by deafult, it should not be available to MyClass.