Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- springjdbc
- Model
- @
- c:if
- @ResponseBody
- jointpoint
- 의존주입
- MVC
- 비즈니스레이어
- gradle
- 스프링
- SpringBoot
- @Valid
- 바인딩변수
- @RequestParam
- .xml
- application.properties
- 어노테이션
- springmvc
- @RequestMapping
- 유효성검사
- after-throwing
- 생성자주입
- Java
- 서비스레이어
- PointCut
- produces
- AOP
- spring
- frontController
Archives
- Today
- Total
메모장
오답노트 02. 본문
728x90
반응형
class A {
int apple;
String banana;
void func(int num) {
num++;
this.apple++;
}
}
public class TEST {
public static void main(String[] args) {
int apple;
A a=new A();
/////System.out.println(apple);/////
System.out.println(a.apple);
Q1. //////16번 라인/////의 에러 원인은? apple의 변수를 초기화 하지 않았다.
Q2. 16번 라인의 에러를 해결하는 방법은?
// 변수를 만든 후
// "데이터(값,value)"를 저장 해보자 !
// data = 100; // ---> 초기화
// = : 대입 연산자
// 값이 저장된게 없는데 어떻게 보여줘야 할까 ?
// => "초기화"라는 작업을 해야함!
// : 변수에 최초로 값을 저장하는 작업
int num=123;
a.func(num);
System.out.println(num);
System.out.println(a.apple);
Q3. num의 값이 123으로 유지되는 이유는?
<메서드 시그니처 >
함수 3요소 (모두 가져야 함수로 인정)
1) input,인자, 입력값, 파라미터, args, 매개변수,인수
2) output, 반환,return, 결과값
3) 기능
메서드 사용의 장점 : "코드를 재사용 할 수 있게 해줌"
:오류의 파급효과 절감
:개발시간 , 비용 단축
:이익 증가
: 유지보수 용이
1. 함수끼리는 메모리 공간을 공유하지 않는다.
2. 전위 증감연산자 >> 함수호출 >> 후위증감연산자
3. 함수를 호출할때에는 "값(value)" 을 전달함 // "변수,주소" 를 전달 xxxx
" call by value" (값에 의한 호출) : '값'을 넘겨주는 호출방식
Q4. num의 값이 124로 변경되기위한 방법은? output을 int로 바꿔 정수 값을 반환 해주면 된다.
String str="banana";
if(a.banana.equals(str)) { <------- NullPointerException 발생
System.out.println("확인 1");
} else {
System.out.println("확인 2");
}
Q5. 29번 라인의 NullPointerException 에러 원인은? a.banana가 생성자 초기화가 안되어있어
null 이기 때문에 나온 에러이다.
Q6. 29번 라인의 에러를 해결하는 방법은? 클래스 A에서 멤버변수인 banana를 초기화 한다.
-> 생성자가 필요하다 .
class A {
int apple;
String banana;
A(int apple, String banana){
this.apple = apple;
this.banana = banana;
}
void func(int num) {
num++;
this.apple++;
}
}
728x90
반응형