Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
24 views1 page

Program 1 Program 2 Program 3: Public Class Arraysederhanamethod Class Data

The document compares three programs that print arrays. Program 1 prints an array within a class using a for loop. Program 2 prints an array by creating an object of a class that defines a private method. Program 3 is similar but defines the array and method as public to allow calling from another class. The key notes that for Programs 2 and 3, an object must be created to call the method, and that Program 2's private method requires changing to public to allow access from outside the class.

Uploaded by

Burhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views1 page

Program 1 Program 2 Program 3: Public Class Arraysederhanamethod Class Data

The document compares three programs that print arrays. Program 1 prints an array within a class using a for loop. Program 2 prints an array by creating an object of a class that defines a private method. Program 3 is similar but defines the array and method as public to allow calling from another class. The key notes that for Programs 2 and 3, an object must be created to call the method, and that Program 2's private method requires changing to public to allow access from outside the class.

Uploaded by

Burhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

PROGRAM 1 PROGRAM 2 PROGRAM 3

public class arraySederhanaBiasa { public class arraySederhanaMethod { class Data {


public static void main(String[] args) { public int[] dataArray = {8, 9, 4, 7, 6, 1, 5, 3}; public int[] dataArray = {8, 9, 4, 7, 6, 1, 5, 3};
int[] dataArray = {8, 9, 4, 7, 6, 1, 5, 3}; private void tampil(){ public void tampil(){
for(int i=0;i<5;i++){ for(int i=0;i<5;i++){ for(int i=0;i<5;i++){
System.out.print(dataArray[i]+" "); System.out.print(dataArray[i]+" "); System.out.print(dataArray[i]+" ");
System.out.println(""); System.out.println(""); System.out.println("");
} } }
} } }
} public static void main(String[] args) { }
arraySederhanaMethod a = new
arraySederhanaMethod(); class arraySederhanaClass {
System.out.println("Menampilkan array"); public static void main(String[] args) {
a.tampil(); Data a = new Data();
System.out.println("Menampilkan array");
} a.tampil();
} }
}

Ket : Ket :
- Terdapat satu class dengan prosedur. Untuk - Terdapat dua class(warna merah). Untuk
pemanggilan prosedurnya dengan membuat objek pemanggilan prosedurnya dengan membuat
(tulisan warna biru). Cara seperti ini bisa dilakukan jika objek (tulisan warna biru).
pada fungsi/prosedur tidak menggunakan static. - Penggunaan private (tulisan warna hijau pada
- Penggunaan private (tulisan warna hijau) hanya bisa program 2) tidak bisa karena hanya bisa
diakses oleh class itu sendiri. diakses oleh class itu sendiri, maka harus
diganti dengan public (tulisan warna hijau).

You might also like