fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public class a_a2 { //主類別
  11.  
  12. public static void main(String[] args) {
  13. Creditcard myAccount = new Creditcard();
  14. myAccount.cardName = "Paul";
  15. myAccount.cardNo = 12345678;
  16. myAccount.balance = 50000;
  17. myAccount.show(); //使用 "呼叫" 的方式來傳遞資料。 "物件名稱.方法名稱();"
  18.  
  19. Creditcard myAccount1 = new Creditcard();
  20. myAccount1.cardName = "Mary";
  21. myAccount1.cardNo = 98763542;
  22. myAccount1.balance =200000;
  23. myAccount1.show();
  24. }
  25.  
  26. }
  27.  
  28. class Creditcard //自建類別
  29. {
  30. String cardName; //屬性-cardName
  31. int cardNo; //屬性-cardNo
  32. double balance; //屬性-balance
  33.  
  34. void show() //方法
  35. {
  36. System.out.println("持有人名字為: " + cardName +
  37. "\n卡號為: " + cardNo +
  38. "\n可刷金額為: " + balance + " 元"+"\n");
  39. }
  40. }
  41. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:13: error: non-static variable this cannot be referenced from a static context
		Creditcard myAccount = new Creditcard();
		                       ^
Main.java:19: error: non-static variable this cannot be referenced from a static context
		Creditcard myAccount1 = new Creditcard();
		                        ^
Main.java:12: error: Illegal static declaration in inner class Ideone.a_a2
	public static void main(String[] args) {
	                   ^
  modifier 'static' is only allowed in constant variable declarations
3 errors
stdout
Standard output is empty