int[0][0] int[0][1] int[0][2] int[0][3]
int[1][0] int[1][1] int[1][2] int[1][3]
int[2][0] int[2][1] int[2][2] int[2][3]
public class JavaPractice {
public static void main(String[] args) {
int[][] arr = new int[3][4];
int num = 1;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
arr[i][j] = num;
num++;
}
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
System.out.print(arr[i][j] + "\t");
}
System.out.println();
}
}
}
[Console]
public class JavaPractice {
public static void main(String[] args) {
int[][] arr = { { 11 }, { 22, 33 }, { 44, 55, 66 } };
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
System.out.print(arr[i][j] + "\t");
}
System.out.println();
}
}
}
[Console]
class Man {
String name;
public void tellYourName() {
System.out.println("My Name is " + name);
}
}
class BusinessMan extends Man {
String company;
String position;
public BusinessMan(String name, String company, String position) {
this.name = name;
// super.name = name;
this.company = company;
this.position = position;
}
public void tellYourInfo() {
System.out.println("My company is " + company);
System.out.println("My position is " + position);
tellYourName();
}
}
public class JavaPractice {
public static void main(String[] args) {
BusinessMan man = new BusinessMan("YOON", "Hybrid ELD", "Staff Eng.");
man.tellYourInfo();
}
}
[Console]
My company is Hybrid ELD
My position is Staff Eng.
My name is YOON
class Man {
String name;
Man(String name){
this.name = name;
}
}
class BusinessMan extends Man {
String company;
String position;
public BusinessMan(String name, String company, String position) {
// super.name = name; 은 에러
super(name);
this.company = company;
this.position = position;
}
}
class SuperClass {
public SuperClass() {
System.out.println("Super Class");
}
}
class SubClass extends SuperClass {
public SubClass() {
System.out.println("Sub Class");
}
}
public class JavaPractice {
public static void main(String[] args) {
new SubClass();
}
}
이 코드는 컴파일러가 넣어준 것이 아닌, 개발자가 넣어준 코드이다.
class A {
public A() {
}
}
class B extends A {
public B() {
super();
}
}
public class JavaPractice {
public static void main(String[] args) {
A a = new A();
B b = new B();
}
}
class TV {
private int size;
public TV(int size) {
this.size = size;
}
protected int getSize() {
return size;
}
}
class ColorTV extends TV {
private int color;
public ColorTV(int size, int color) {
super(size);
this.color = color;
}
public int getColor() {
return color;
}
public void printProperty() {
System.out.println(super.getSize() + "인치 " + this.getColor() + "컬러");
}
}
public class JavaPractice {
public static void main(String[] args) {
ColorTV myTV = new ColorTV(32, 1024);
myTV.printProperty();
}
}
[Console]
32인치 1024 컬러