1public class method{
2 public static void sayHello(){
3 System.out.println("Hello World");
4 }
5}
6public class app{
7 public static void main(String[] args){
8 method m = new method(); // Creating an instance from our class
9 m.sayHello(); // using the class methods by the instance we created.
10 }
11}
11_ you should first create an instance from this class.
22_ once you create one, you use it for calling the class methods.
1class A {
2
3 public void a1 ( ) {
4 }
5
6 private void a2 ( ) {
7 }
8}
9
10class B {
11
12 private A objA = new A ( );
13
14 public void b1 ( ) {
15 // Call to method a1. This works.
16 objA.a1 ();
17 }
18
19 void b2 ( ) {
20 // Call to method a2. This will give compile error.
21 objA.a2 ();
22 }
23}
1public class Alpha {
2 public void DoSomethingAlpha() {
3 Beta cbeta = new Beta();
4 cbeta.DoSomethingBeta(); //?
5 }
6}
7
1public class Alpha extends Beta{
2 public void DoSomethingAlpha() {
3 DoSomethingBeta(); //?
4 }
5}
6