abstract 추상
//
abstract class Person{ // 다른 클래스들이 공통으로 갖는 부분을 적기 위해서만 존재하는 클래스 -> 얘로는 직접 객체를 생성할수 없다.
int age ;
String name;
abstract void speak(); //추상메소드 ( 이 메소드는, 나를 상속받은 클래스들이 모두 가져야하는 메소드예요!)
}
class Student extends Person{
void speak() { //overriding 덮어쓰기 재정의
System.out.println("im stu.. ");
}
}
class Teacher extends Person{
void speak() {
System.out.println("im teacher!!");
}
}
class Main{
public static void main(String[] args) {
Student s = new Student();
Teacher t = new Teacher();
s.speak();
}
}*/
/*
abstract class Calculator{
public abstract int add(int a, int b);
public abstract int subtract (int a, int b);
public abstract double average (int[] a);
}
class Main extends Calculator{
public int add(int a, int b) {
return a+b;
}
public int subtract(int a, int b) {
return a-b;
}
public double average(int[] a) {
double sum=0;
for (int i=0;i<a.length;i++)
sum+=a[i];
return sum/a.length;
}
public static void main(String[] args) {
Main c= new Main();
System.out.println(c.add(2,3));
System.out.println(c.subtract(2,3));
System.out.println(c.average(new int [] {2,3,4}));
}
}
*/
//1.
/*
abstract class A{
abstract void F();
}*/
//2
/*
abstract class A{
void f() {}
}
class B extends A{}*/
//3
/*
abstract class A{
void F() {}
}
class B extends A{
void F() {}
public static void main(String [] args) {
B b=new B();
b.f();
}
}
추상클래스 : 일반메소드+추상메소드 extends
인터페이스 : 일반메소드.(x) implements
*/
/*
interface A{
abstract void f();
}
interface B extends A{
abstract void f1();
}
class Main implements B{
public static void main(String[] args) {
}
}*/
import java.util.Scanner;
abstract class converter{
abstract protected double convert(double src);
abstract protected String getSrcString();
abstract protected String getDestString();
protected double ratio;
public void run() {
Scanner scanner=new Scanner(System.in);
System.out.println(getSrcString()+"을"+getDestString()+"로 바꿉니다.");
System.out.println(getSrcString()+"을 입력하세요>> ");
double val = scanner.nextDouble();
double res = convert(val);
System.out.println("변환결과: "+res+getDestString()+"입니다");
scanner.close();
}
}
class Won2Dollar extends converter{
public Won2Dollar(double x) {
ratio=x;
}
protected double convert(double src) {
return src/ratio;
}
protected String getSrcString() {
return "원";
}
protected String getDestString() {
return "달러";
}
}
class Main{
public static void main(String[] args) {
Won2Dollar to = new Won2Dollar(1200);
to.run();
}
}