4Àå

Similar documents
Microsoft PowerPoint - 4장

Microsoft PowerPoint - java1-lecture4.ppt [호환 모드]

JAVA PROGRAMMING 실습 02. 표준 입출력

(Microsoft PowerPoint - java1-lecture4.ppt [\310\243\310\257 \270\360\265\345])

JAVA PROGRAMMING 실습 05. 객체의 활용

JAVA PROGRAMMING 실습 02. 표준 입출력

5장.key

자바 프로그래밍

JAVA PROGRAMMING 실습 05. 객체의 활용

chap10.PDF

Design Issues

PowerPoint Presentation

비긴쿡-자바 00앞부속

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

q 이장에서다룰내용 1 객체지향프로그래밍의이해 2 객체지향언어 : 자바 2

01-OOPConcepts(2).PDF

02 C h a p t e r Java

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

(Microsoft PowerPoint - java2-lecture3.ppt [\310\243\310\257 \270\360\265\345])

PowerPoint Presentation

1

예제 2) Test.java class A intvar= 10; void method() class B extends A intvar= 20; 1"); void method() 2"); void method1() public class Test 3"); args) A

쉽게 풀어쓴 C 프로그래밍

05-class.key

(8) getpi() 함수는정적함수이므로 main() 에서호출할수있다. (9) class Circle private double radius; static final double PI= ; // PI 이름으로 로초기화된정적상수 public

Spring Data JPA Many To Many 양방향 관계 예제

PowerPoint 프레젠테이션

JAVA PROGRAMMING 실습 08.다형성

Microsoft Word - java19-1-midterm-answer.doc

gnu-lee-oop-kor-lec06-3-chap7

Microsoft PowerPoint - Java7.pptx

<4D F736F F F696E74202D20C1A63038C0E520C5ACB7A1BDBABFCD20B0B4C3BC4928B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

PowerPoint 프레젠테이션

Java ~ Java program: main() class class» public static void main(string args[])» First.java (main class ) /* The first simple program */ public class

쉽게 풀어쓴 C 프로그래밍

PowerPoint Presentation

(Microsoft Word - \301\337\260\243\260\355\273\347.docx)

PowerPoint Presentation

Connection 8 22 UniSQLConnection / / 9 3 UniSQL OID SET

JAVA PROGRAMMING 실습 02. 표준 입출력

PowerPoint Presentation

PowerPoint Presentation

09-interface.key

JAVA 프로그래밍실습 실습 1) 실습목표 - 메소드개념이해하기 - 매개변수이해하기 - 새메소드만들기 - Math 클래스의기존메소드이용하기 ( ) 문제 - 직사각형모양의땅이있다. 이땅의둘레, 면적과대각

PowerPoint Presentation

쉽게 풀어쓴 C 프로그래밍

PowerPoint Presentation

Java ...

Microsoft PowerPoint - Lect04.pptx

JAVA PROGRAMMING 실습 07. 상속

07 자바의 다양한 클래스.key

PowerPoint Presentation

유니티 변수-함수.key

슬라이드 1

int total = 0; for( int i=1; i<=5; i++ ) { for( int j=1; j<=i; i++ ) { total ++; System.out.println( total ); 대구분 : 객체와 Class 소구분 : 객체생성과사용 / Class 선언

rmi_박준용_final.PDF

PowerPoint Presentation

PowerPoint Presentation

Microsoft PowerPoint - 2강

PowerPoint Presentation

C++ Programming

슬라이드 1

<4D F736F F F696E74202D2036C0CFC2B05FB0B4C3BCC1F6C7E2C7C1B7CEB1D7B7A1B9D62E707074>

제 1 강 희망의 땅, 알고리즘

제11장 프로세스와 쓰레드

Microsoft Word - EEL2 Lab4.docx

교육자료

Modern Javascript

초보자를 위한 자바 2 21일 완성 - 최신개정판

Microsoft PowerPoint - 04-UDP Programming.ppt

Microsoft PowerPoint - 14주차 강의자료

untitled

PowerPoint 프레젠테이션

03-JAVA Syntax(2).PDF

Microsoft PowerPoint 자바-기본문법(Ch2).pptx

JAVA PROGRAMMING 실습 09. 예외처리

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

ch09

Microsoft PowerPoint - hci2-lecture12 [호환 모드]

PowerPoint Presentation

초보자를 위한 C# 21일 완성

Microsoft PowerPoint - java1-lab5-ImageProcessorTestOOP.pptx

10.0pt1height.7depth.3width±â10.0pt1height.7depth.3widthÃÊ10.0pt1height.7depth.3widthÅë10.0pt1height.7depth.3width°è10.0pt1height.7depth.3widthÇÁ10.0pt1height.7depth.3width·Î10.0pt1height.7depth.3width±×10.0pt1height.7depth.3width·¡10.0pt1height.7depth.3width¹Ö pt1height.7depth.3widthŬ10.0pt1height.7depth.3width·¡10.0pt1height.7depth.3width½º, 10.0pt1height.7depth.3width°´10.0pt1height.7depth.3widthü, 10.0pt1height.7depth.3widthº¯10.0pt1height.7depth.3width¼ö, 10.0pt1height.7depth.3width¸Þ10.0pt1height.7depth.3width¼Ò10.0pt1height.7depth.3widthµå

Contents Contents 2 1 Abstract 3 2 Infer Checkers Eradicate Infer....

[ 프로젝트이름 ] : Project_Car [ 프로젝트를만든목적 ] : 임의의자동차판매소가있다고가정하고, 고객이원하는자동차의각부분을 Java 를이용하여객 체로생성하고, 그것을제어하는메소드를이용하여자동차객체를생성하는것이목표이다. [ 프로젝트패키지와클래스의내용설명 ] [

슬라이드 1

Java

Contents. 1. PMD ㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍ 2. Metrics ㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍ 3. FindBugs ㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍ 4. ㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍ

12-file.key

class Sale void makelineitem(productspecification* spec, int qty) SalesLineItem* sl = new SalesLineItem(spec, qty); ; 2. 아래의액티비티다이어그램을보고 Java 또는 C ++,

교육2 ? 그림

chapter6.doc

PowerPoint 프레젠테이션

JMF2_심빈구.PDF

歯JavaExceptionHandling.PDF

@OneToOne(cascade = = "addr_id") private Addr addr; public Emp(String ename, Addr addr) { this.ename = ename; this.a

Microsoft PowerPoint - Chapter 6.ppt

Transcription:

클래스와 객체 O b j e c t i v e s 객체 지향적 언어와 절차 지향적 언어의 개념을 이해하고 서로 비교한다. 메소드 오버로딩의 개념을 이해하고 오버로딩된 메소드를 호 출한다. 객체 지향적 언어의 특성을 안다. 생성자를 작성하고 생성자의 용도에 대해 안다. 자바에서 클래스를 선언하는 방법을 안다. 가비지의 개념을 이해하고 가비지 컬렉션을 실행한다. 클래스와 객체의 의미를 알고 구분한다. 접근 지정자 default, private, protected, public을 안다. 자바에서 객체 생성 방법을 안다. static의 의미를 알고, static 멤버의 특징을 안다. 메소드 작성 방법과 호출 방식을 안다.

C H A P T E R JAVA PROGRAMMING Object Oriented Language Structured Procedural Programming Language life cycle

CHAPTER C flow chart

JAVA JAVA PROGRAMMING modeling 1 2 3 (a) (b) Encapsulation TV

CHAPTER TV TV On/Off TV class method field information hiding

JAVA JAVA PROGRAMMING String name; int age; void speak(); void eat(); void study(); (field) (method) Inheritance super class sub class Animal Human Animal Human Human Animal nameage eat()sleep()love() Animal Human Animal Human hobbyjobwork()cry()laugh()

CHAPTER class Animal { String name; int age; void eat() {... void sleep() {... void love() {... Animal String name; int age; void eat(); void sleep(); void love(); Human class Human extends Animal { String hobby; String job; void work() {... void cry() {... void laugh() {... String name; int age; void eat(); void sleep(); void love(); String hobby; String job; void work(); void cry(); void laugh(); Animal Human Polymorphism 5...

JAVA JAVA PROGRAMMING CHECK TIME 2 2 instance object instance

CHAPTER 5 A 28 O 7 AB

JAVA JAVA PROGRAMMING class class public class Person { public String name; public int age; public Person() { public Person(String s) { name = s; (field) (constructor) (constructor) public String getname() { return name; (method) public public public { class Person Person class { field public constructor constructor

CHAPTER method public Person public static void main (String args[]) { Person aperson; // aperson aperson = new Person(" "); // Person aperson.age = 30; String s = aperson.getname(); (1) Person aperson; aperson Person (2) aperson = new Person(" "); aperson name " " age Person(String s) {... getname() {... (3) aperson.age = 30; aperson name " " age 30 Person() {... getname() {... () String s = aperson.getname(); aperson name " " s " " age 30 Person() {... getname() {return name;

JAVA JAVA PROGRAMMING Person Person aperson; // aperson Person aperson Person (1) C++ Person aperson; aperson aperson Person new Person; C++ new new new aperson = new Person(" "); (2) Person aperson new Person Person(String s) { name... aperson age 30

CHAPTER aperson.age = 30; (3) aperson age int i = aperson.age; aperson getname() () String s = aperson.getname(); Goods Goods Goods String nameint pricenumberofstocksold Goods main() Goods camera camera name Nikon price 00000 numberofstock 30 sold 50 1 2 3 5 6 7 8 9 10 11 12 13 1 15 16 17 18 public class Goods { String name; int price; int numberofstock; int sold; public static void main(string[] args) { Goods camera = new Goods(); // camera.name = "Nikon"; camera.price = 00000; camera.numberofstock = 30; camera.sold = 50; System.out.println(" :" + camera.name); System.out.println(" :" + camera.price); System.out.println(" :" + camera.numberofstock); System.out.println(" :" + camera.sold);

JAVA JAVA PROGRAMMING :Nikon :00000 :30 :50 MyExp MyExp MyExp base exp 2 3 base 2 exp 3base exp MyExp getvalue() getvalue() base exp base 2 exp 3 getvalue() 8 1 2 3 5 6 7 8 9 10 11 12 13 1 15 16 17 18 19 20 21 22 public class MyExp { int base; int exp; int getvalue() { int res=1; for(int i=0; i<exp; i++) // base exp res = res * base; return res; public static void main(string[] args) { MyExp number1 = new MyExp(); number1.base = 2; number1.exp = 3; MyExp number2 = new MyExp(); number2.base = 3; number2.exp = ; base2 exp3 res1*2*2*2 System.out.println("2 3 = " + number1.getvalue()); System.out.println("3 = " + number2.getvalue()); 2 3 = 8 3 = 81

CHAPTER Person[] pa; pa = new Person[10]; for(int i=0; i<pa.length; i++) { pa[i] = new Person(); pa[i].age = 30 + i; for(int i=0; i<pa.length; i++) // pa age System.out.print(pa[i].age + " "); Person Person pa Person[] pa; Person[10] pa; //. 10 pa = new Person[10]; // Person 10. Person

JAVA JAVA PROGRAMMING Person for (int i=0;i<pa.length;i++) { pa[i] = new Person(); // Person() pa[i].age = 30 + i; // Person age 30+i. Person Person Person[] pa; pa = new Person[10]; for(int i=0; i<pa.length; i++) { pa[i] = new Person(); pa[i].age = 30 + i; pa pa pa Person pa[0] pa[1] pa[2] pa[3] pa[] pa[5] pa[6] pa[7] pa[8] pa[9] pa[0] pa[1] pa[2] pa[3] pa[] pa[5] pa[6] pa[7] pa[8] pa[9] age=30 age=31 age=32 age=33 age=3 age=35 age=36 age=37 age=38 age=39 pa Person i pa[i]

CHAPTER pa[i].age = 30 + i; i Person age 30+i Person age for (int i=0; i<pa.length; i++) System.out.print(pa[i].age + " "); 30 31 32 33 3 35 36 37 38 39 java.util.scanner Goods Goods Goods 3 1 2 3 5 6 7 8 9 10 11 12 13 1 15 16 17 18 19 20 import java.util.scanner; public class GoodsArray { public static void main(string[] args) { Goods [] goodsarray; // goodsarray = new Goods[3]; // Goods Scanner s = new Scanner(System.in); for(int i=0; i<goodsarray.length; i++) { String name = s.next(); // int price = s.nextint(); // int n = s.nextint(); // int sold = s.nextint(); // goodsarray[i] = new Goods(name, price, n, sold); // Goods for(int i=0; i<goodsarray.length; i++) { System.out.print(goodsArray[i].getName()+" "); // System.out.print(goodsArray[i].getPrice()+" "); // System.out.print(goodsArray[i].getNumberOfStock()+" "); // System.out.println(goodsArray[i].getSold()); //

JAVA JAVA PROGRAMMING 1 21 22 23 2 25 26 27 28 29 30 31 32 33 3 35 36 37 38 39 0 1 class Goods { private String name; private int price; private int numberofstock; private int sold; Goods(String name, int price, int numberofstock, int sold) { // this.name = name; this.price = price; this.numberofstock = numberofstock; this.sold = sold; String getname() {return name; // int getprice() {return price; // int getnumberofstock() {return numberofstock; // int getsold() {return sold; // 500 10 20 1000 20 30 2000 30 50 500 10 20 1000 20 30 2000 30 50 CHECK TIME String nameint agefloat heightweight Human String name 2 main() ahuman Human name age 21height 180.5weight 73.2 5 Human 2

CHAPTER method overloading public int getsum(int i, int j) { int sum; sum = i + j; return sum; public private protected.6 public private protected getsum() return sum; int sum int void

JAVA JAVA PROGRAMMING call-by-value argument passing callby-value bytecharshortintlongfloatdoubleboolean caller Person setage() n main() a33 setage() n 3 a public class Person { public String name; public int age; public class CallByValue { public static void main (String args[]) { Person aperson = new Person(" "); int a = 33; aperson.setage(a); a 33 33 public Person(String s) { name = s; setage()n n 33 3 public void setage(int n) { age = n; n++; System.out.println(a); 33 setage()n 33 call-by-value

CHAPTER class MyInt { int val; MyInt(int i) { val = i; public class CallByValueObject { public static void main(string args[]) { Person aperson = new Person(" "); MyInt a = new MyInt(33); aperson.setage(a); System.out.println(a.val); public class Person { public String name; public int age; public Person(String s) { name = s; public void setage(myint i) { age = i.val; i.val++; MyInt a = new MyInt(33); a MyInt val 33 aperson.setage(a); public void setage(myint i) a i a i val 33 ia i.val++; a i val 3 MyInt val 1 System.out.println(a.val); 3 a val 3 setage() i

JAVA JAVA PROGRAMMING MyInt setage() a setage() setage() i a MyInt setage() i val a val setage() main() a increase() increase() array a increase() array 1 increase() a 2 3 5 6 public class ArrayParameter { public static void main(string args[]) { int a[] = {1, 2, 3,, 5; increase(a); for(int i=0; i a.length; i++) System.out.print(a[i]+" "); a 1 2 2 3 3 5 5 6 array static void increase(int[] array) { for(int i=0; i array.length; i++) { array[i]++; 2 3 5 6

CHAPTER char ' ' ',' 1 2 3 5 6 7 8 9 10 11 12 13 1 15 16 17 18 public class ArrayParameter { static void replacespace(char a[]) { for (int i = 0; i < a.length; i++) if (a[i] == ' ') a[i] = ','; // ',' static void printchararray(char a[]) { for (int i = 0; i < a.length; i++) System.out.print(a[i]); // System.out.println(); // public static void main (String args[]) { char c[] = {'T','h','i','s',' ','i','s',' ','a',' ','p','e','n','c','i','l','.'; printchararray(c); // replacespace(c); // printchararray(c); // amain() c This is a pencil. This,is,a,pencil. method overloading

JAVA JAVA PROGRAMMING 2 getsum() class MethodOverloading { // public int getsum(int i, int j) { return i + j; public int getsum(int i, int j, int k) { return i + j + k; class MethodOverloadingFail { // public int getsum(int i, int j) { return i + j; public double getsum(int i, int j) { return (double)(i + j); getsum() getsum()

CHAPTER MethodSample 3 getsum() main() MethodSample getsum() main() MethodSample getsum() public static void main(string args[]) { MethodSample a = new MethodSample(); int i = a.getsum(1, 2); int j = a.getsum(1, 2, 3); double k = a.getsum(1.1, 2.2); public class MethodSample { public int getsum(int i, int j) { return i + j; public int getsum(int i, int j, int k) { return i + j + k; public double getsum(double i, double j) { return i + j; this this this this this this this

JAVA JAVA PROGRAMMING class Samp { int id; public Samp(int x) {this.id = x; public void set(int x) {this.id = x; public int get() {return id; this this Samp this.id Samp id this Samp get()this return id; id this.id return this.id; // return id; this set() void set(int id) {id = id; id = id; // id id. 2 id set(int id) id id set(int id)id id id this void set(int id) {this.id = id;

CHAPTER this this this main() Samp 3 this ob1ob2ob3 this main() ob1.set() this ob1 ob2.set() this ob2 public class Samp { int id; public Samp(int x) {this.id = x; public void set(int x) {this.id = x; public int get() {return this.id; ob1 id 35... void set(int x) {this.id = x;... public static void main(string [] args) { Samp ob1 = new Samp(3); Samp ob2 = new Samp(3); Samp ob3 = new Samp(3); ob2 id... 3 6 void set(int x) {this.id = x;... ob1.set(5); ob2.set(6); ob3.set(7); ob3 id... 3 7 void set(int x) {this.id = x;... this main() Samp 2 Samp ob1 = new Samp(3); Samp ob2 = new Samp(); Samp s;

JAVA JAVA PROGRAMMING s = ob2; s ob2 s ob2 ob1 = ob2; ob1 ob2 ob2 ob1 ob2 ob1 garbage.5 public class Samp { int id; public Samp(int x) {this.id = x; public void set(int x) {this.id = x; public int get() {return this.id; public static void main(string [] args) { Samp ob1 = new Samp(3); Samp ob2 = new Samp(); Samp s; s = ob2; ob1 = ob2; // System.out.println("ob1.id="+ob1.id); System.out.println("ob2.id="+ob2.id); ob1 id... 3 void set(int x) {this.id = x;... ob2 id... void set(int x) {this.id = x;... s ob1.id= ob2.id=

CHAPTER double getsum() CHECK TIME

JAVA JAVA PROGRAMMING public class Samp { int id; public Samp(int x) { this.id = x; public Samp() { this.id = 0; public void set(int x) {this.id = x; public int get() {return this.id; public static void main(string [] args) { Samp ob1 = new Samp(3); Samp ob2 = new Samp(); Samp s; // Samp() public class Samp { public Samp(int x) {... // new new Samp ob1 = new Samp(3); // Samp(int x)

CHAPTER Samp public class Samp { public Samp(int x) {... // public Samp() {... // new Samp ob1 = new Samp(3); // Samp ob2 = new Samp(); // public Samp(int x) {this.id = x; void new Samp(3) 3 ob1 id 3

JAVA JAVA PROGRAMMING Book String titlestring authorint ISBN 3 1 2 3 5 6 7 8 9 10 11 12 13 1 15 public class Book { String title; String author; int ISBN; public Book(String title, String author, int ISBN) { // this.title = title; this.author = author; this.isbn = ISBN; public static void main(string [] args) { Book javabook = new Book("Java JDK", " ", 3333); // Book 3 3 main() Book title "Java JDK"author " "ISBN 3333 default constructor class Book { public Book() { // main()

CHAPTER new DeafultConstructor p = new DefaultConstructor(); new DefaultConstructor(); DefaultConstructor.java public class DefaultConstructor { int x; public void setx(int x) {this.x = x; public int getx() {return x; public static void main(string [] args) { DefaultConstructor p = new DefaultConstructor(); p.setx(3); public class DefaultConstructor { int x; public void setx(int x) {this.x = x; public int getx() {return x; public DefaultConstructor() { public static void main(string [] args) { DefaultConstructor p = new DefaultConstructor(); p.setx(3); main() new

JAVA JAVA PROGRAMMING DefaultConstructor p1 = new DefaultConstructor(3); new public DefaultConstructor(int x) { this.x = x; new DefaultConstructor p1 = new DefaultConstructor(); //. new new public class DefaultConstructor { int x; public void setx(int x) {this.x = x; public int getx() {return x; public DefaultConstructor() { public DefaultConstructor(int x) { this.x = x; public static void main(string [] args) { DefaultConstructor p1 = new DefaultConstructor(3); int n = p1.getx(); DefaultConstructor p2 = new DefaultConstructor(); p2.setx(5); this() this()

CHAPTER this() 3 public class Book { String title; String author; int ISBN; public Book(String title, String author, int ISBN) { this.title = title; this.author = author; this.isbn = ISBN; public Book(String title, int ISBN) { this(title, "Anonymous", ISBN); public Book() { this(null, null, 0); System.out.println(""); public static void main(string [] args) { Book javabook = new Book("Java JDK", " ", 3333); Book holybible = new Book("Holy Bible", 1); Book emptybook = new Book(); title = "Holy Bible" author = "Anonymous" ISBN = 1 title = "Holy Bible" ISBN = 1 Book this() main() Book Book holybible = new Book("Holy Bible", 1); title ISBN Holy Bible 1 this(title, "Anonymous", ISBN); 3 public Book(String title, String author, int ISBN) {...

JAVA JAVA PROGRAMMING titleauthorisbnholy BibleAnonymous 1 this() this() this() this() this() this() this() Book 3 public Book() { System.out.println(" "); this(null, null, 0); //. new destructor new available memory C++ new delete delete delete

CHAPTER new garbage garbage collector class Samp { int id; public void Samp(int x) { this.id = x; public void Samp() { System.out.println(" "); this(0); CHECK TIME class ConstructorExample{ int x; public void setx(int x) {this.x = x; public int getx() {return x; public ConstructorExample(int x) { this.x = x; public static void main(string [] args) { ConstructorExample a = new ConstructorExample(); int n = a.getx(); this this()

JAVA JAVA PROGRAMMING new Person a = new Person(" "); b = new Person(" "); b = a; b a b Person Person ab Person a, b; a = new Person(" "); b = new Person(" "); b = a; // b a b Person " " Person " "

CHAPTER 1 2 3 5 6 7 8 9 10 11 public class GarbageEx { public static void main(string[] args) { String a = new String("Good"); String b = new String("Bad"); String c = new String("Normal"); String d, e; a = null; d = c; c = null; (a) main() 6 3 (b) a "Good" a null "Good" b "Bad" b "Bad" c "Normal" c null "Normal" d d e e null (a) (b)

JAVA JAVA PROGRAMMING 0 garbage collector System Runtime gc() System Runtime gc() System.gc(); //

CHAPTER CHECK TIME String s1 = ""; String s2 = s1; int[] a; a = new int[10]; String a = new String(""); String b = new String(""); String c; c = a; a = null; public static void main(string [] args) { printhello(); private static void printhello() { String hello = new String("Hello!"); System.out.println(hello);

JAVA JAVA PROGRAMMING (private)

CHAPTER privateprotectedpublic default public 2 public 2 public public AccessSample.class UseSample.class UseSample AccessSample AccessSample public public class AccessSample {... // AccessSample public //. class UseSample { AccessSample a; // AccessSample public... public void f() { a = new AccessSample(); // AccessSample public...... default default default 6

JAVA JAVA PROGRAMMING default private protected public default default public public B public C A public B public n g() ACB public ng() P class A { void f() { B b = new B(); b.n = 3; b.g(); public class B { public int n; public void g() { n = 5; class C { public void k() { B b = new B(); b.n = 7; b.g(); public private private private private private A

CHAPTER B private ng() A P A B B private B class A { void f() { B b = new B(); b.n = 3; b.g(); public class B { private int n; private void g() { n = 5; class C { public void k() { B b = new B(); b.n = 7; b.g(); private protected protected protected protected 5 B protected ng() C A B D n g() protected class A { void f() { B b = new B(); b.n = 3; b.g(); public class B { protected int n; protected void g() { n = 5; P class C { public void k() { B b = new B(); b.n = 7; b.g(); B protected C B D A DB class D extends B { void f() { n = 3; g(); protected

JAVA JAVA PROGRAMMING default B C A default package-private default default C B ng() A P class A { void f() { B b = new B(); b.n = 3; b.g(); public class B { int n; void g() { n = 5; class C { public void k() { B b = new B(); b.n = 7; b.g(); 1 2 3 5 6 7 8 9 10 11 12 13 1 class Sample { public int a; private int b; int c; // public class AccessEx { public static void main(string[] args) { Sample aclass = new Sample(); aclass.a = 10; aclass.b = 10; aclass.c = 10; Exception in thread "main" java.lang.error: Unresolved compilation problem: The field Sample.b is not visible at AccessEx.main(AccessEx.java:11)

CHAPTER 11 aclass.b = 10; Sample a c publicdefault AccessEx b private AccessEx Sample private get/set 1 2 3 5 6 7 8 9 10 11 12 13 1 15 16 17 18 19 20 21 class Sample { public int a; private int b; int c; // public int getb() { return b; public void setb(int value) { b = value; public class AccessEx { public static void main(string[] args) { Sample aclass = new Sample(); aclass.a = 10; aclass.setb(10); aclass.c = 10; public private public private public public

JAVA JAVA PROGRAMMING CHECK TIME FieldAccess.java class SampleClass { public int field1; protected int field2; int field3; private int field; public class FieldAccess { public static void main(string[] args) { SampleClass fa = new SampleClass(); fa.field1 = 0; fa.field2 = 1; fa.field3 = 2; fa.field = 3; MethodAccess.java class SampleClass2 { public void method1() { protected void method2() { private void method3() { void method() { public class MethodAccess extends SampleClass2 { // MethodAccess SampleClass void method5() { method3(); public static void main(string[] args) { MethodAccess ma = new MethodAccess(); ma.method1(); ma.method2(); ma.method(); ma.method5(); public

CHAPTER non-static static non-static static non-static static static static static

JAVA JAVA PROGRAMMING class StaticSample { int n; // non-static void g() {... // non-static static int m; // static static void f() {... // static static non-static non-static static static static static non-static non-static static non-static non-static static non-static class Sample { int n; void g() {... static class Sample { static int m; static void g() {...

CHAPTER static.static.static static C/C++ global variable static static StaticSample static static static main() StaticSample static m f() StaticSample s1, s2; static m f() s1s2 s1s2 static ng()h() s1 = new StaticSample(); s2 = new StaticSample(); static s1.m = 50; s2.f(); static s1 s2 static s1s2 g()h() static m

JAVA JAVA PROGRAMMING class StaticSample { public int n; public void g() { m = 20; public void h() { m = 30; public static int m; public static void f() { m = 5; public class Ex { public static void main(string[] args) { StaticSample s1, s2; s1 = new StaticSample(); s1.n = 5; s1.g(); s1.m = 50; // static s2 = new StaticSample(); s2.n = 8; s2.h(); s2.f(); // static System.out.println(s1.m); StaticSample s1, s2; s1 = new StaticSample(); s1.n = 5; s1.g(); s1.m = 50; f() {... m 20 f() {... s1 n 5 m g() { m=20; h() { m=30; m 50 f() {... s1 n 5 s1s2 g() { m=20; h() { m=30; m 30 f() {... static mf() s1.g() staticm 20 s1.m=50; staticm 50 5 s1 n 5 n 8 s2 s2 = new StaticSample(); s2.n = 8; s2.h(); g() { m=20; h() { m=30; g() { m=20; h() { m=30; s2.h() staticm 30 s1s2 m 5 f() { m=5; s2.f() static m 5 s2.f(); s1 n 5 g() { m=20; h() { m=30; n 8 g() { m=20; h() { m=30; s2 System.out.println(s1.m); 5 static

CHAPTER static static.static main().static new static StaticSample.m = 10; static s1.f(); // static f() StaticSample.f(); // static f() StaticSample.h(); // h() non-static StaticSample.g(); // g() non-static static

JAVA JAVA PROGRAMMING class StaticSample { public int n; public void g() { m = 20; public void h() { m = 30; public static int m; public static void f() { m = 5; public class Ex { public static void main(string[] args) { StaticSample.m = 10; StaticSample.m = 10; StaticSample s1; s1 = new StaticSample(); System.out.println(s1.m); s1 m 10 f() {... m 10 f() {... n g() { m=20; h() { m=30; 10 static s1 StaticSample s1; s1 = new StaticSample(); System.out.println(s1.m); s1.f(); StaticSample.f(); s1.f(); s1 m 5 f() { m=5; n g() { m=20; h() { m=30; s1.f() static m 5 10 m 5 f() { m=5; StaticSample.f() staticm 5 StaticSample.f(); s1 n g() { m=20; h() { m=30; static static static static static

CHAPTER C C++ global variable global function static JDK java.lang.math static java.lang.math public class Math { static int abs(int a); static double cos(double a); static int max(int a, int b); static double random();... Math Math m = new Math(); // int n = m.abs(-5); static int n = Math.abs(-5); // static static

JAVA JAVA PROGRAMMING static static static static static static class StaticMethod { int n; void f1(int x) {n = x; // void f2(int x) {m = x; // static int m; static void s1(int x) {n = x; //. static non-static static void s2(int x) {f1(3); //. static non-static static void s3(int x) {m = x; //. static static static void s(int x) {s3(3); //. static static static this static this static this class StaticAndThis { int n; static int m; void f1(int x) {this.n = x; // void f2(int x) {this.m = x; // non-static static static void s1(int x) {this.n = x; //. static this

CHAPTER static static 1 2 3 5 6 7 8 9 10 11 12 13 1 15 16 17 18 19 20 class CurrencyConverter { private static double rate; // public static double todollar(double won) { return won/rate; // public static double tokwr(double dollar) { return dollar * rate; // public static void setrate(double r) { rate = r; //. KWR/$1 public class StaticMember { public static void main(string[] args) { CurrencyConverter.setRate(1121); // $1 1121 System.out.println("" + CurrencyConverter.toDollar(1000000) + "."); System.out.println("" + CurrencyConverter.toKWR(100) + "."); 982.060660128885 112100.0

JAVA JAVA PROGRAMMING CHECK TIME static static public class Sample{ static int a; public static void seta(int x) { this.a = x; static main() public class StaticCheck { int s; static int t; public static void main(string [] args) { StaticCheck.t = 10; StaticCheck.s = 20; StaticCheck obj = new StaticCheck(); obj.s = 30; obj.t = 0; System.out.println(obj.s); System.out.println(obj.t);

CHAPTER final final final final final FinalClass DerivedClass final class FinalClass {... class DerivedClass extends FinalClass { //... final final final public class SuperClass { protected final int finalmethod() {... class DerivedClass extends SuperClass { // DerivedClass SuperClass protected int finalmethod() {... //, final final

JAVA JAVA PROGRAMMING public class FinalFieldClass { final int ROWS = 10; //, (10) final int COLS; //, void f() { int[] intarray = new int[rows]; // ROWS = 30; //. final. public static final final final FinalFieldClass final static public static final class SharedClass { public static final double PI = 3.11592653589793;

CHAPTER class new.. call by value this new this() public default privateprotecteddefault public static static static final final final

JAVA JAVA PROGRAMMING Open Challenge n n WordGameAppPlayer Player sayword() succeed() WordGameApp main() Player [] String String word =" "; int lastindex = word.length() - 1; char lastchar = word.charat(lastindex); char firstchar = word.charat(0); // // //

CHAPTER EXERCISE String manufacturernamecountryregionkind int yeargrade Wine private 3 Wine manufacturer name class Car { private String name; private int speed; private char gear; public String getname() { return name; public void setname(string str) { name = str; public int getspeed() { return speed; public void setspeed(int s) { speed = s; public char getgear() { return gear;

JAVA JAVA PROGRAMMING public void setgear(char c) { gear = c; class MyClass { int i; public class Example { public static void main (String args[]) { MyClass a; a.i = 10; class Person { private String name; private int age; public class Example { public static void main (String args[]) { Person aperson = new Person(); aperson.name = " "; aperson.age = 17;

CHAPTER class SampleClass { public void addandstore(int i, int j) { i = i + j; public class Example { public static void main (String args[]) { SampleClass aclass = new SampleClass(); int num = 15; aclass.addandstore(num, 10); System.out.println(num); class ClassSample { public int doadd(int i, int j) { return i + j; public float doadd(int i, int j) { return (float)(i + j); class MyClass { int i; public class Example { public static void main (String args[]) { MyClass a[] = new MyClass[10]; for (int j = 0; j < a.length; j++) { a[j].i = j;

JAVA JAVA PROGRAMMING public class Example { int num; public void setnum(int num) { num = num; public int getnum() { return num; public static void main(string [] args) { Example obj = new Example(); obj.setnum(20); System.out.println(obj.getNum()); public class Example { int num; String name; public Example(int i, String s) { num = i; name = s; public Example(int i) { this(i, null); public Example() { System.out.println(" "); this(0, null); public static void main(string [] args) { Example obj1 = new Example(1); Example obj2 = new Example();

CHAPTER class MyClass { int i; public class Example { public static void main (String args[]) { MyClass a = new MyClass(); MyClass b = new MyClass(); MyClass c = b; int i = 10; int j = 0; int k = 0; k = i; a = b; default public protected private class SampleClass { private int id; public static int getid() { return id; public static void setid(int id) { this.id = id; public class Example { public static void main() {

JAVA JAVA PROGRAMMING SampleClass obj = new SampleClass(); obj.setid(10); System.out.println(obj.getId()); C C++ String a = new String("aa"); String b = a; String c = b; a=null; b=null; String s = null; for(int i=0; i<10; i++) { s = new String("hello"+i); System.out.println(s);

CHAPTER Song Song title artist album composer year track show() ABBA Dancing Queen Song show() Rectangle int x1y1x2y2 2 x1y1x2y2 void set(int x1, int y1, int x2, int y2) x1y1x2y2 int square() void show() boolean equals(rectangle r) r true Rectangle main() main() public static void main(string args[]) { Rectangle r = new Rectangle(); Rectangle s = new Rectangle(1,1,2,3); r.show(); s.show(); System.out.println(s.square()); r.set(-2,2,-1,); r.show(); System.out.println(r.square()); if(r.equals(s)) System.out.println(".");

JAVA JAVA PROGRAMMING static ArrayUtility ArrayUtility static double [] inttodouble(int [] source); // int double static int [] doubletoint(double [] source); //double int static ArrayUtility2 ArrayUtility2 static int [] concat(int [] s1, int [] s2); // s1 s2 static int [] remove(int [] s1, int [] s2); // s1 s2 +- * / AddSubMulDiv int ab void setvalue(int a, int b) int calculate() int a int b setvalue() calculate() int a int b setvalue() calculate() int a int b setvalue() calculate() int a int b setvalue() calculate() Add Sub Mul Div main() AddSubMulDiv setvalue() calculate()

CHAPTER S A B 10