import java.util.*;
class Point {
private int x,y;
public Point(int x,int y) {this.x=x;this.y=y;}
public int getX() {return x;}
public int getY() {return y;}
protected void move(int x,int y) {this.x=x;this.y=y;}
}
class ColorPoint extends Point{
private String color;
public ColorPoint(int x,int y,String color) {
super(x,y);
this.color=color;
}
public void setPoint(int x,int y){
move(x,y);
}
public void setColor(String color) {
this.color=color;
}
public void show() {
System.out.println(color+"색으로"+"("+getX()+","+getY()+")");
}
}
class Main{
public static void main(String[] args) {
ColorPoint cp=new ColorPoint(5,5,"YELLOW"); //ColorPoint 객체 생성
cp.setPoint(10, 20);
cp.setColor("GREEN");
cp.show();
}
}
class
abstract class 추상클래스 (일부만 작성된 클래스)
interface 인터페이스 (틀만 있는 클래스)
import java.util.*;
interface StackInterface {
int length(); //추상메소드 (내용이 작성이 안된 메소드)
String pop();
boolean push(String ob);
}
class StringStack implements StackInterface {
private int top=-1; //top이 마지막 데이터의 위치
String stack[] = new String[5];
//추상메소드들 구현
public int length() {
return top+1;
}
public String pop() {
return stack[top--];
}
public boolean push(String ob) {
if(top!=4){
top++;
stack[top]=ob;
return true;
}
else return false;
}
}
class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
StringStack cp=new StringStack();
for(int i=0;i<5;i++) {
String str = sc.next();
cp.push(str);
}
for(int i=0;i<5;i++) {
System.out.print(cp.pop()+" ");
}
}
}
import java.util.*;
interface Shape {
final double PI=3.14;
void draw();
double getArea();
default public void redraw() {
System.out.println("--- 다시 그립니다. ---");
draw();
}
}
class Circle implements Shape {
private int radius;
public Circle (int radius) {
this.radius=radius;
}
public void draw() {
System.out.print("반지름 "+radius);
}
public double getArea() {
return radius*radius*PI;
}
}
public class Main {
public static void main(String[] args) {
Shape coin=new Circle(10);
coin.redraw();
System.out.print(" 코인의 면적은"+coin.getArea());
}
*/}