Java Reference
In-Depth Information
Three classes are defined,
AClass
,
BClass
and
CClass
.
AClass
has (non-static)
method
methodA1
. Now
BClass
wants to use that method.
CClass
is the 'master'
class which uses both
AClass
and
BClass
. The structure is listed below.
1.
class
AClass{
2.
3.
public
AClass(){
4.
}
5.
6.
public int
methodA1(){
7.
//
commands
8.
}
9.
}
10.
11.
-----------------------------------
12.
13.
class
BClass{
14.
15.
public
BClass(){
16.
}
17.
18.
public void
methodB1(){
19.
int
n=methodA1();
20.
//
methodA1 unknown
21.
}
22.
23.
24.
}
25.
26.
27.
-----------------------------------
28.
29.
class
CClass{
30.
31.
public
CClass(){
32.
}
33.
34.
public static void
main(String[] a){
35.
AClass a =
new
AClass();
36.
BClass b =
new
BClass();
37.
}
38.
39.
}
This will result in a compile-time error at the line
int
n=methodA1();
Search WWH ::
Custom Search