ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 객체생성
    자바/순수자바 2022. 11. 18. 17:21
    package testjava;
    
    
    public class Board {
    	
    	private  static int bno; // 필드 
    	
    	public int setboard() { return this.bno;} // 메소드1
    	public int getboard() {return this.bno;} // static 메소드2
    	
    }
    
    
    
    
    
    package testjava;
    
    public class Board2 {
    	public static int bno;
    	
    	private static Board2 board = new Board2(); // 싱글톤
    	public static Board2 getInstance() {return board;} 
    	
    	public  int setboard () {return bno;}  // 메소드1
    	public  int getboard() { return bno;} // static 메소드2
    	
    }
    
    
    
    
    
    
    
    package testjava;
    
    public class test {
     // getboard() 와 setboard() [호출하는 방법 -5가지]
    	
    	// 1. new 를 쓰는방법
    	Board2 boardtest = new Board2();
    	int testvalue1 = boardtest.getboard();
    	int testvalue2 = boardtest.setboard();
    	
    	
    	// 2. @Autowird
    //	@Autowird
    	private Board2 board3;
    	int testvalue5 = board3.getboard();
    	int testvalue6 = board3.setboard();
    	
    	
    	// 싱글톤 
    	Board2 boardObject = Board2.getInstance();
    	int testvalue3 = boardObject.getboard();
    	int testvalue4 = boardObject.setboard();
    	
    	
    	
    	
    }

    '자바 > 순수자바' 카테고리의 다른 글

    mvc1 mvc2 차이점  (0) 2023.01.10
    super, super() 용도  (0) 2022.12.24
    [Java] toString()과 String.valueOf()의 차이점  (0) 2022.12.23
    비트연산자  (0) 2022.10.03
    jvm  (1) 2022.09.29

    댓글

Designed by Tistory.