Java8 [JAVA] static이란 무엇인가!! 자바 프로그램에서 오류가 발생된 부분을 찾는 문제를 푸는중.. static으로 선언된 get 메소드로 인해 컴파일러 오류가 발생된 부분이 이해되지 않아서 이것저것 찾아 보았다. 문제를 다 쓰기 귀찮으니 ㅎㅎ.. 간략해서 적는다.. class Person { private String name; public Person(String val) { name = val; } public static String get() { return name; } } public class Test { public static void main(String[] args) { Person obj = new Person("kim"); System.out.println(obj.get()); } } 여기서 return name 부.. 2024. 4. 11. [JAVA] 다형성 왜 쓸까? 아래의 코드가있다. 여기서 생성자를 Berry A = new Apple(); 으로 A 변수를 선언한 이유가 궁금했다. class Berry { String Str; void meth() { func(); } void func() { System.out.println(Str); } } class Apple extends Berry { String Str; void func() { Str = "Apple"; super.Str = "Berry"; super.func(); System.out.println(Str); } } public class Gisafirst { public static void main(String[] args) { Berry A = new Apple(); A.meth(); } } 왜.... 2024. 4. 10. java) 주석과 세미클론 주석(comment) 주석은 프로그래밍적으로 해석되지 않는다. 한줄 주석 public static void main(String[] args) { // 두개의 변수가 같은 데이터 타입 일 때 아래와 같이 코드를 작성한다. String a, b; } JavaDoc 주석 /** * Prints an integer and then terminate the line. This method behaves as * though it invokes {@link #print(int)} and then * {@link #println()}. * * @param x The int to be printed. */ public void println(int x) { synchronized (this) { print(x); n.. 2022. 2. 27. java)5일차 변수 변수선언 하기. 정수 : int a를 정수형으로 선언하다. class CodingEveryBody { public static void main (String[] args) throws java.lang.Exception { int a; a = 1; System.out.println(a+1); //2 a = 2; System.out.println(a+1); //3 } } 상수: double double a = 1.1; System.out.println(a+1.1); // 2.2 a = 2.1; System.out.println(a+1.1); // 3.2 문자열 데이터타입 변수만들기. first 를 선언하면서 , 변수의값에 할당하는방법. String first = "coding"; System.out.pr.. 2022. 2. 27. 이전 1 2 다음