My footsteps
package pkg1; public class MyParentTest { public static void main(String[] args) { Myparent p = new Myparent(); System.out.println(p.prv);//클래스 내애서만 가넝한 System.out.println(p.dft); System.out.println(p.dft); System.out.println(p.dft); } } class Myparent { private int prv; //같클 int dft; //같패 protected int prt; //같패+자손(다패 자손) public int pub; //자유ㅋ public void PrintMembers() { System.out.println(prv..
public class Over { public static void main(String[] args) { Child C = new Child(); C.String(); } } class Parent { int x = 10; } class Child extends Parent{ int x = 20; void String() { //굳이 매서드를 만들어서 main매서드 에서 호출하는 이유는,main"매서드"이기 때문에 class는 직접호출할수없다. System.out.println("this.x = "+this.x); System.out.println("super.x = "+super.x); } }
public class Over { public static void main(String[] args) { YourPoint t = new YourPoint(); //자손your이 부모Point의 상속을 받고 있으니 객체를 자손으로 만들면됨. 어차피 부모값까지 딸려옴 t.x = 3; t.y = 5; t.z = 7; System.out.println(t.getLocation()); //오버라이딩된 자손 클래스를 호출함. } } class Point { int x; int y; String getLocation() { //매개변수가 없어서, return "x = "+x+"y = "+y; //값을 return으로 String 형태로 반환. Sop쓰면 오류남 } } class YourPoint extends ..
public class arr { public static void main(String[] args) { mm c = new mm(); System.out.println(c.toString()); System.out.println(c); } } class mm extends Object { int r; MyPoint p; mm(){ p = new MyPoint(); //객체선언은 매서드 안에서만 할수있는갑다..그래서 mm()을 만들어줘야하는듯? } } //mm매서드에서 객체 p를 만들어주고 → mm매서드보다 더큰 mm클래스를 main으로 호출해서 → main매서드에서 class mm의 객체 c 만들어줌
public class Test { public static void main(String[] args) { Circle c = new Circle(); c.p.x = 1; c.p.y = 3; c.r = 5; //왜 c.p.r이 아니냐면, class Circle의 객체를 main에서 만들었다. 그래서 객체 c가 범위가 가장 크다. //그리고 나서 그 객체안에 또 객체p가 생성되었다. 그럼 왜 p.r은 에러가 나느냐? //이름을 보면 알수있다.MyPoint class의 객체를 Circle class에서 만들었기 때문에 객체 p는 MyPoint의 멤버인 x,y만 가질수 있는거다. System.out.println(c.p.x + c.p.y); } } class MyPoint { int x; int y; } c..