/*class Arrayutill {
public static int[] concat(int[] a, int[] b) {
int[] c = new int[a.length+b.length];
for(int i = 0 ; i<a.length ; i++) {
c[i] = a[i];
}
for(int i = 0 ; i<b.length ; i++) {
c[i+a.length] = b[i];
}
return c;
}
public static void print(int[] a) {
System.out.print("[");
for (int i = 0; i < a.length; i++)
System.out.print(a[i]+" ");
System.out.print("]");
}
}
class Main {
public static void main(String[] args) {
int[] array1 = { 1, 5, 7, 9 };
int[] array2 = { 3, 6, -1, 100, 77 };
int[] array3 = Arrayutill.concat(array1, array2);
Arrayutill.print(array3);
}
}
메소드 오버라이딩 (재정의)
메소드 오버로딩 (같은 이름의 메소드이지만, 다른 매개변수를 갖는 메소드)
이름이 같은 메소드를 생성
*
*/
/*
class Point {
private int x,y;
public void set(int x, int y) {
this.x = x;
this.y = y;
}
void showPoint() {
System.out.println("점의 좌표는 룰루라라라라라ㅏ라라라("+x+",루루루루루루ㅜ루루루루루라라라ㅏ라라[라ㅏ"+y+")끝");
}
void showPoint(int n){ //메소드 오버로딩
}
}
class Ee extends Point {
private String color;
public void setColor(String color) {
this.color = color;
}
public void showColorpoint() {
System.out.println(color);
showPoint();
}
void showPoint() { //오버라이딩 (재정의)
System.out.println("colorpoint");
}
}
public class Main{
public static void main(String[] args) {
Point p = new Point();
p.set(1, 2);
p.showPoint();
Ee e = new Ee();
e.set(3, 4);
e.setColor("red");;
e.showColorpoint();
}
}
class Noodle{
private String color;
private int size;
protected void setColor(String color) {
this.color=color;
}
Noodle (){
this.size = 10;
}
Noodle (String color)
{
this.size=50;
this.color = color;
}
void show() {
System.out.println("size : "+size);
System.out.println("color : "+color);
}
}
class Ramyun extends Noodle{
private String name;
Ramyun(){
setColor("yellow");
}
Ramyun(String color){
super(color); //부모의 생성자 호출시 맨 위에 작성해야함!!!!
show();
}
}
class Main{
public static void main(String[] args) {
Ramyun jin = new Ramyun();
jin.show();
Ramyun shin = new Ramyun("red");
shin.show();
}
}
class Point {
private int x, y;
public Point() {
this.x = this.y = 0;
}
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public void showPoint() {
System.out.println("(" + x + "," + y + ")");
}
}
class ColorPoint extends Point {
private String color;
public ColorPoint(int x, int y, String color) {
super(x, y);
this.color = color;
}
public void showColorPoint() {
System.out.println(color);
showPoint();
}
}
public class Main{
public static void main(String[] args) {
ColorPoint cp = new ColorPoint(5, 6, "blue");
cp.showColorPoint();
}
}
추상클래스 : abstract
추상메소드를 포함하고 있다 -> 추상 클래스
추상클래스는 객체생성이 물가능하다. but 레퍼런스변수는 생성 가능
*/
abstract class Person{ //추상 클래스
int age;
String name;
abstract void speak(); //추상메소드
void sleep() {
System.out.println("잠자기");
}
}
class Student extends Person{
void speak() { //추상메소드를 오버라이딩
System.out.println("저는 학생이예요");
}
}
class Main{
public static void main(String[] args) {
//Person p ; (o)
//p = new Person(); (x)
,
Student s = new Student();
s.speak();
s.sleep();
}
}