하위폴더 1 : public
package com.nate; //컴파일 명령어 cmd> 해당경로 접근 후 javac -d . 파일명.java
public class Information
{
String name = "Information 조현";
int age = 35;
public Information(){}
public void output(){
System.out.println(name+" = "+age);
}
public String getName(){
return name;
}
}
하위폴더 2 : public + protected
package com.nate;
public class Student
{
String name = "Student 조현";
String school = "가산초등학교";
public Student(){}
protected void prn(){
System.out.println(name+" = "+school);
}
}
=====================================================================
메인
import com.nate.Information;
import com.nate.Student;
class StartMain extends Student
{
StartMain(){}
void test(){
prn();
}
public static void main(String[] args)
{
SchoolInfor si = new SchoolInfor(); //동일 폴더에 있는 객체 : 무조건 실행
si.output();
Information i = new Information(); //하위 폴더에 있는 객체 : public 필요(범용)
i.output();
//System.out.println("i.name = "+i.name);
System.out.println("i.getName = "+i.getName());
Student s = new Student(); //하위 폴더에 있는 객체 : public과 protected 활용
//s.prn(); //메소드가 protected이기 때문에 상속받아 사용할 수 있다.
StartMain sm = new StartMain();
sm.prn();
}
}
'응용 SoftWare > JAVA' 카테고리의 다른 글
static (0) | 2016.12.01 |
---|---|
private (0) | 2016.12.01 |
package ComFile (0) | 2016.12.01 |
상속 관계에서 객체 형변환 (0) | 2016.12.01 |
클래스 상속 (0) | 2016.12.01 |