Archive for the oop Category

การสร้างตัวแปร Array ของ Java นั้น มีอยู่ประมาณ 2 ประเภทครับ มาดูกันเลย

1. การสร้างตัวแปรที่เป็นมารตฐานของ Java อยู่แล้ว เช่น int float double เป็นต้น

รูปแบบ datatype ชื่อตัวแปร [] = new datatype[จำนวนความยาวของ Array] ; หรือ

datatype[] ชื่อตัวแปร  = new datatype[จำนวนความยาวของ Array] ;

ตัวอย่าง

int a = new Int[50] ;
double[] b = new Double[12] ;

2. การสร้าง Array ของวัตถุ รูปแบบคล้ายเคียงกัน

รูปแบบ  ชื่อ class ชื่อตัวแปร = new ชื่อ class [ความยาว] ; หรือ
ชื่อ class[] ชื่องัตถุ = new ชื่อ class[ความยาว] ;

เช่น

Student student[] = new Student[30] ;
Student[] student = new Student[22];

VN:F [1.7.9_1023]
Rating: 0.0/10 (0 votes cast)
VN:F [1.7.9_1023]
Rating: 0 (from 0 votes)
  • Share/Bookmark