3초기억력

상속 : 문제1)평균 클래스를 상속을 받아서 평균과 총점을 구하는 하위 클래스를 생성 본문

자바_기초

상속 : 문제1)평균 클래스를 상속을 받아서 평균과 총점을 구하는 하위 클래스를 생성

잠수콩 2019. 5. 27. 09:04
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
//평균 클래스를 상속을 받아서 평균과 총점을 구하는 하위 클래스를 생성

package Inheritance;

class Avg{
	double avg;
	
	Avg(){}		//없으면 오류
	
	Avg(double avg){
		this.avg = avg;
	}
	
	void average(int sum) {
		avg = (double)sum / 2;
		//avg = sum / 2.0;		실수로 변환하기 위한.
		System.out.println("평균 : " + avg);
	}
}

class Total extends Avg{
	int total;
	int math;
	int eng;
	
	Total(int math, int eng) {
		
		this.math = math;
		this.eng = eng;
		this.total = this.math + this.eng;
		
		System.out.println("총점 : " + this.total);
		average(this.total);
		
	}
	
	
	
	
}


public class exam_CreditTest {

	public static void main(String[] args) {
		
		Total t1 = new Total(50, 100);
		System.out.println("평균2 : " + t1.avg);
		

	}

}
Comments