Hi,
A Class did not declare Public then i can run both Class in the same file..But in
SCJP Cathy Seira Book (1.6)
mentioned (page number 11) that in a source file there should be one Public. If i didnt not declare any public i can access any class from command prompt.
Code :
-----
package com;
class
Test {
public static void main(
String[] args) {
// TODO Auto-generated method stub
int $x = 10;
System.out.println(/* printing x vlaue */$x);
}
}
class Test1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int $x = 20;
System.out.println(/* printing x vlaue */$x);
}
}
Output:
--------
D:\Eclipse\Workspace\Test1\src>javac com/Test1.java
error: cannot read: com/Test1.java
1 error
D:\Eclipse\Workspace\Test1\src>javac com/Test.java
D:\Eclipse\Workspace\Test1\src>
java com/Test
10
D:\Eclipse\Workspace\Test1\src>java com/Test1
20