Git Product home page Git Product logo

class-'s Introduction

classvariable

package s21319_java02; //클래스 정의 class Circle{ static int radius =10; //class 자료형 필드 반지름 //int radius =5; // // instance 반환형 메소드 String color = "Black"; // instance 자료형 필드 색상 double calcArea() { //반환형 메소드 return 3.14 * radius * radius; //해당 값 리턴 } } public class S21319_99_ValueClass {

public static void main(String[] args) {
	Circle a;	//참조 변수 선언
	a = new Circle();	//객체 생성
	//a.radius = 100;
	//a.radius = "Red";
	double area = a.calcArea();	//객체 메소드 접근
	System.out.println("a필드색상 : "+a.color+" 원의 면적 ="+area+" radius:"+a.radius);
	
	Circle b;	//참조 변수 선언
	b = new Circle();	//객체 생성
	b.radius = 20;	//객체 필드 접근
	b.color = "white";	//객체 필드 접근
	area = b.calcArea();	//객체 메소드 접근
	System.out.println("b필드색상 : "+b.color+" 원의 면적 ="+area+" radius:"+b.radius);
	
	Circle c;	//참조 변수 선언
	c = new Circle();	//객체 생성
	area = c.calcArea();	//객체 메소드 접근
	System.out.println("c필드색상 : "+c.color+" 원의 면적 ="+area+" radius:"+c.radius);
	
	//static 전역, 클래스변수 자바를 기동할때 생김 전체가 사용!
}

} image

실행화면입니다.

class-'s People

Contributors

wjdgkdms avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.