Or add braces around the assignments to make an initialization block: { acc[0] = new Account(200.0, 100, “SSUET1”, ’s’); acc[1] = new Account(300.0, 101, “SSUET2”, ’s’); acc[2] = new Account(400.0, 102, “SSUET3”, ’s’); acc[3] = new Account(500.0, 103, “SSUET4”, ’c’); acc[4] = new Account(600.0, 104, “SSUET5”, ’c’); }
Scott > On Jan 31, 2022, at 6:40 AM, Pieter van den Hombergh > <pieter.van.den.hombe...@gmail.com> wrote: > > > Same error as before. > At the class level, each line must start with a type. You need to move the > assignments to the array element to the constructor or inside curlies > directly behind the array declaration. > > > Acoounts[] acc = new Account[] { new Account(....),....} ; > >> On Mon, Jan 31, 2022, 04:54 Zulfi Khan <zulfi6...@yahoo.com.invalid> wrote: >> Hi, >> I am trying to create an array of Object of Account class: >> public class RButtArrListJFrame extends javax.swing.JFrame { >> ArrayList<Account> al_allAcc = new ArrayList<>(); >> //ArrayList<String> al_sav = new ArrayList<String>(); >> DefaultListModel <String> model = new DefaultListModel<String>(); >> Account[] acc = new Account[5]; >> acc[0] = new Account(200.0, 100, "SSUET1", 's');//Error >> acc[1] = new Account(300.0, 101, "SSUET2", 's');//Error >> acc[2] = new Account(400.0, 102, "SSUET3", 's');//Error >> acc[3] = new Account(500.0, 103, "SSUET4", 'c');//Error >> acc[4] = new Account(600.0, 104, "SSUET5", 'c');//Error >> >> I am getting the message: >> ‘]’ expected, invalid method declaration return type required. I have >> attached the image and account class file. Account class is given below: >> public class Account { >> private double balance; >> private int number; >> String name; >> char accType; >> Account(){ >> balance = 0.0; >> number = 0; >> final String name = "0"; >> accType ='\0'; >> } >> Account(double dBal, int iNum, String strName, char chAccType){ >> balance = dBal; >> number = iNum; >> name = strName; >> accType = chAccType; >> } >> Account (Account accObj){ >> balance = accObj.balance; >> number = accObj.number; >> name = accObj.name; >> accType = accObj.accType; >> } >> double getBalance(){ >> return balance; >> } >> int getNumber(){ >> return number; >> } >> char getAccType(){ >> return accType; >> } >> void setBalance(double b){ >> balance =b; >> } >> } >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@netbeans.apache.org >> For additional commands, e-mail: users-h...@netbeans.apache.org >> >> For further information about the NetBeans mailing lists, visit: >> https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists