자바의 정석 문제풀이
-
Book_364_7_18자바의 정석 문제풀이 2021. 8. 19. 17:50
상속 //참조변수와 인스턴스의 연결 class Parent{ int x=100; void method() { System.out.println("Parent Method"); } } class Child extends Parent{ //상속 int x=200; void method() { System.out.println("Child Method"); } } public class Book_364_7_18 { public static void main(String[] args) { Parent p=new Child(); Child c=new Child(); System.out.println("p.x= "+p.x); p.method(); System.err.println("c.x= "+c.x); c.met..
-
Book_366_7_20자바의 정석 문제풀이 2021. 8. 19. 17:48
상속 class Parent1{ int x=100; void method() { System.out.println("Parent Method"); } } class Child1 extends Parent1{ int x=200; void method() { System.out.println("x="+x); //this.x와 같다 System.out.println("super.x= "+super.x); System.out.println("this.x= "+this.x); } } public class Book_366_7_20 { public static void main(String[] args) { Parent1 p=new Child1(); Child1 c=new Child1(); System.out.pr..
-
Book_368_7_21자바의 정석 문제풀이 2021. 8. 19. 17:47
다형성 class Product{ int price; int bonusPoint; public Product(int price) { this.price=price; bonusPoint=(int)(price/10.0); //보너스점수는 제품가격의 10% } } class Tv extends Product{ Tv(){ //부모클래스의 생성자 product(int price)를 호출 super(100); //tv의 가격 } //object클래스의 tostring()을 오버라이딩 public String toString() {return "Tv";} } class Computer extends Product{ Computer(){super(200);} public String toString() {return ..
-
Book_218_5_19(2차원배열+과목별 점수)자바의 정석 문제풀이 2021. 8. 10. 17:33
//2차원 배열 int[][]score= { {100,100,100}, {20,20,20}, {30,30,30}, {40,40,40}, {50,50,50} }; //과목별 총점 int kortotal=0,engtotal=0,mathtotal=0; System.out.println("번호\t국어\t영어\t수학\t총점\t평균"); System.out.println("============================"); for(int i=0;i