일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- 에러페이지
- HTML
- 국제화
- JSP
- 안드로이드
- Menu
- 메소드
- struts2
- 클래스
- 기본
- 생성자
- 예외처리
- layout
- Graphic
- Java
- 이클립스
- 전화걸기
- Eclips
- mybatis
- paint
- 어노테이션
- AWT
- 메서드
- oracle
- OGNL
- 배열
- 오버로딩
- Spring
- Android
- JavaScript
- Today
- Total
목록전체 글 (572)
note
package com.trans; public class Transport { protected String name; protected int speed; protected int energy; //protected boolean swim; public String getName(){ return name; } public int getSpeed(){ return speed; } public int getEnergy(){ return energy; } public void consumGas(){ energy -= 10; } } package com.trans; public class TransportMain { public static void main(String[] args){ Ship s = ne..
package com.over2;//메소드 오버라이딩 super참조 변수 class A{ public void make(){ System.out.println("부모 클래스"); } } class B extends A{ public B(){ //super : 슈퍼클래스 (부모 클래스)를 가리키는 //레퍼런스 변수 super.make(); } public void make(){//메소드 오버라이딩 System.out.println("자식 클래스"); } } public class Exten02 { public static void main (String[] args){ B bp = new B(); bp.make(); //부모 값과 자식값 둘다 가져오게 된다 } } 부모 클래스 자식 클래스
package com.over;//메서드 오버라이딩 class Parent{ protected void make(){ System.out.println("부모 클래스"); } } class Child extends Parent{ //메소드 오버라이딩(메소드 재정의) 메소드 오버라이딩 규칙 틀은 같으나 내용이 다름 //부모 클래스 메소드의 확장 또는 재정의 protected void make(){ System.out.println("자식 클래스"); } } public class Exten01 { public static void main(String[] args){ Child ch = new Child(); //목적은 재사용 이 아니라 확장, 재정의(리모델링) //메소드 오버라이딩으로 부모 클래스가 호출..
package com.ext2;//상속 접근 지정자 살펴보기 class Point2D{ private int x=10; //private 접근제한의 경우 //상속관계의 자식클래스 에서호출불가 protected int y=20; int z = 30; public int getX(){//캡슐화로 가져다 쓰기 return x; } } class Point3D extends Point2D{ public void print(){ //X가 접근 제한이 private 이기 때문에 호출불가 //System.out.println(x +", "+y+ ", "+z); //사용하려면 private - > protected로 변경 //메소드 생성후 은닉화 해서 캡슐화로 가져다 쓰기 System.out.println(y+", "..
package com.ext3;//상속으로 핸드폰 만들기1 public class CellPhone { //휴대폰 기본 기능을 제공하는 클래스 //private면은 가져다 쓸수 없지만 protected는 사용가능 protected String model; protected String number; protected int chord; public String getModel(){ return model; } public int getChord(){ return chord; } public String getNumber(){ return number; } } package com.ext3; public class CellPhoneMain { public static void main(String[] ar..
package com.ext2;//슈퍼 클래스와 서브 클래스 만드는 예제 class Parent{ public void parentPrn(){ System.out.println("슈퍼 클래스 메서드는 상속된다."); } } //Parent를 슈퍼클래스로 하는 서브 클래스 child정의 class Child extends Parent{ public void childPrn(){ System.out.println("서브 클래스 메서드는 슈퍼가 사용못한다."); } } public class SuperSub01 { public void main(String[] args){ Child c = new Child();//서브클래스로 객체를 생성 //그 상위의 부모클래스를 메모리에 저장함parent랑 object둘다..
국,영,수 입력받아 평균 학점 출력하기 package com.exam; public class Score { private int korean; private int english; private int math; public void setKorean(int korean){ this.korean = korean; } public void setEnglish(int english){ this.english = english; } public void setMath(int math){ this.math = math; } public int getKorean(){ return korean; } public int getEnglish(){ return english; } public int getMath(){..
package com.ext;//상속 기본1 class Parent extends Object{//extends Object는 일반적으로 생략가능 int a = 100; } class Child extends Parent{ int b = 200; } public class Exten01 { public static void main(String[] args){ Child c = new Child(); System.out.println("a = "+c.a); System.out.println("b = "+c.b); } } a = 100 b = 200 package com.ext;//상속 기본2 class Parent2{ public void make(){ System.out.println("부모클래스");..
public class StaticEx3 { public static void main(String[] args){ StaticCount sc1 = new StaticCount(); System.out.println("sc1의 c: "+ sc1.c + ", sc1의 count: " + StaticCount.count); StaticCount sc2 = new StaticCount(); System.out.println("sc2의 c: "+ sc2.c + ", sc2의 count: " + StaticCount.count); StaticCount sc3 = new StaticCount(); System.out.println("sc3의 c: "+ sc3.c + ", sc3의 count: " + StaticCo..
public class StaticCount { int c; //인스턴스 변수 static int count; // 클래스(static)변수 /*객체 생성과 무관 호출에 의해 메모리에 올라가서 여러 객체에서 공유할 수 있음*/ public StaticCount(){ c++; count++; } } call 1 call 3 메인 call 2 class StaticTest001{//정적 메서드 정의하기 private static int a=10; private int b=20; public static void SetA(int new_a){ a = new_a; } public static int getA(){ return a; } } public class StaticTest02 { public static..
public class StaticEx1 { int a; //인스턴스 변수 static String s; //클래스(Static)변수 public static void main(String args){ s = "자바의 꿈"; //같은 클래스의 클래스 변수 호출시 클래스명 생략 ex)StaticEx1.s = 자바의꿈; System.out.println("s : " + StaticEx1.s); //인스턴스 변수는 객체 생성 후 호출 가능 //a = 1000; StaticEx1 st1 = new StaticEx1(); st1.a = 1000; } } StaticTest.a->10 s1.a->10 s2.a->10 s1.b->10 s2.b->20 s1.a->100 s2.a->100 s1.b->20 s2.b->20
class StaticTest{//정직 멤버변수와 인스턴스 멤버 변수의 차이점 static int a=10; //클래스(static)에 올라감 int b=20; //heap에 올라감 } public class StaticTest01 { public static void main(String[] args){ System.out.println("StaticTest.a->"+StaticTest.a); StaticTest s1 = new StaticTest(); StaticTest s2 = new StaticTest(); System.out.println("s1.a->"+StaticTest.a+"\t s2.a->" + StaticTest.a); System.out.println("s1.b->"+StaticTes..
public class MethodTest004 { void prn(int ... num){ //int형 데이터를 출력하는 메서드의 정의 for(int i=0; i
동물 객체 만들기 Animal 멤버 필드 : 이름 나이 비행여부 boolean type -은닉화 생성자 멤버 메소드(캡슐화) Animal Main 육상동물(포유류) 생성자 이용해서 데이터 셋팅 출력 이름 나이 (세) 비행여부 (불가능) 조류 포함 class Ani{ //멤버 필드 은닉화 private String name; private int age; private boolean fly; //캡슐화 public void setName(String n){ name = n; } public void setAge(int a){ age = a; } public void setFly(boolean f){ fly = f; } //get name으로 값 가져오기 public String getName(){ retu..
public class ThisTest2 { int a; int b; public ThisTest2(int a,int b){ //생성자 또는 메소드영역에서 //멤버변수와 지역변수의 명칭이 같을때는 //지역변수가 우선 //this.a 는 위에있는 a이고 a는 int a이다 //this는 멤버변수 호출이다 this.a=a; this.b=b; //멤버변수 지역변수 this.print(); } public void print(){ System.out.println(a + "," + b); } public static void main(String[] args){ ThisTest2 t = new ThisTest2(4,5); } } 4,5
public class ThisConEx {//생성자 내에 또다른 생성자를 호출 public ThisConEx(){ /*this()는 생성자 내부에서 또 다른 생성자를 호출할때, 생성자 내부에서 또다른 생성자를 호출할 때는 생성자 최상단에 위치시켜야 함 (다른 수행문 보다 우선적으로 호출되어야함) System.out.println("ThisConEx() 호출");*/ this("엄마"); } public ThisConEx(char[] ch){ this(String.valueOf(ch));//char[] -> String }// - >"my♥SunAe" public ThisConEx(long lo){ this(String.valueOf(lo)); //long -> String } //900000000L -..
public class ThisTest {//레퍼런스 this(생성자) public ThisTest(){ System.out.println("객체생성 : "+this); //참조 변수의 일종 this } public static void main(String[] args){ ThisTest tt = new ThisTest(); System.out.println("객체 생성후 : "+tt); //this는 객체 내부에서만 작동하기 때문에 따로 클래스를 만들어 객체화 } } 객체생성 : ThisTest@c05d3b 객체 생성후 : ThisTest@c05d3b
class MyDate3{//생성자 오버로딩 private int year; private int month; private int day; public MyDate3(){} //밑에 생성자를 만들었기 때문에 위에가 자동적으로 만들어지지 않음 public MyDate3(int new_year, int new_month, int new_day){ year=new_year; month=new_month; day=new_day; } public void print(){ System.out.println(year+ "/" +month+"/"+day); } } public class ConstructorTest05 { public static void main(String[] args){ MyDate3 d= ne..
public class MyClass1 {//MyClass1Test이랑 연결 //메인이 없기에 MyClass1Test랑 연결시킴 //은익화 private String name; //name = null //null = 객체에 주소가 없어 참조 못함 //생성자(오버로딩으로 볼 수 있음) public MyClass1(){} //생성자 public MyClass1(String n){ name = n; } //캡슐화 public void setName(String n){ name=n; } public String getName(){ return name; } } 없음 따로 저장하기 public class MyClass1Test {//MyClass1이랑 연결 public static void main(String..
class MyDate2{//생성자 정의하기 private int year; private int month; private int day; //없어도 됨 (자동으로됨) public MyDate2(){ System.out.println("[생성자] : 객체가 생성될 때 자동 호출됩니다."); year=2011; month=12; day=16; } public void print(){ System.out.println(year + "/" + month + "/" +day); } } public class ConstructorTest02 { public static void main(String[] args){ MyDate2 d = new MyDate2(); d.print(); } } [생성자] : 객체가 ..