본문 바로가기

JAVA

QUIZ 1. [사칙연산] 두 정수(-3만~3만)와 연산자(+, -, *, /)를 입력 받고 계산결과를 출력 package kr.ac.busan; import java.util.Scanner; public class Quiz1 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); System.out.println("입력 : "); int a = Integer.parseInt(input.nextLine()); int b = Integer.parseInt(input.nextLine()); System.out.print("연산자 : "); char ch = (in.. 더보기
상속(inheritance) 상속이란 기존클래스를 확장해서 새로운 클래스를 만드는 기술 언제 상속이 필요한가? - 기존 클래스와 유사한 클래스를 만들어야 할 경우 상속 전 소스 package kr.ac.busanit; class Car { //멤버변수 protected int speed; protected String color; //private는 복사가 안된다. //생성자 public Car() { } //멤버메소드 public void run() { System.out.println("달리다."); } public int getSpeed() { return speed; } public void setSpeed(int speed) { this.speed = speed; } public String getColor() { retu.. 더보기
객체와 클래스(2) 객체를 어떻게 표현할 것인가? - 객체를 생성하는 틀로 사용되는 클래스 - 개념적인 클래스와 자바의 클래스 AccountTest.java package kr.ac.busanit; public class AccountTest { public static void main(String[] args) { // TODO Auto-generated method stub Account myAccount = new Account("111-1111-1111"); myAccount.deposit(1000000); System.out.println("통장잔액은: " + myAccount.getBalence()); myAccount.withdraw(100000); System.out.println("통장잔액은: " + my.. 더보기
캡슐화란? 캡슐화(Encapsulation)의 목적은 정보(자원)의 보호 목적에서 만들어진 개념이다. 자바 언어에서는 캡슐화를 지원하기 위해서 4가지의 접근 제어 지시자가 존재한다. private, protected, (default), public이 있다. 접근 제어 지시자는 클래스, 인스턴스 변수, 인스턴스 메소드 앞에 존재함으로써 접근을 제어할수 있다. public은 해당 요소를 누구나 사용할 수 있다는 뜻이며, private 키워드는 타입을 만든 사람이 아니면 메소드 내부 요소에 접근 할 수 없다. protected는 상속을 받은 자식 클래스에서만 접근 할수 있으며, (default)는 팩키지 내의 클래스에서만 접근 할 수 있다. 하나의 예를 들어서 설명 하도록 하자. public class Car{ pri.. 더보기
C와 JAVA 구조체 비교 C언어 JAVA struct Doggy { int eye; int leg; char[12] name; } void run(){ //뽀삐 달리다. } int main() { struct Doggy bbobbi; struct kitty marry; bbobbi.eye = 2; bbobbi.eye = strcpy(name, "뽀삐"); run(); } class Doggy { //멤버변수 int eye; int leg; String name; //생성자 Doggy(){ } //멤버메소드 void run(){ //뽀삐 달리다. } } public class DoggyTest{ public static void main(String args[]) { Doggy bbobbi = new Doggy(); bbobbi... 더보기