/* 2.1 CONCEPTS */
// java not have global
class kingFishBread { // 붕어빵 틀 = 그냥 object = class
private int calorie; // instance variable, a place to hold data
// private: only use inside the specific (class)
public int howMuch; // anyone can use, even outside class ~= global
String name;
// method(default = empty)
kingFishBread() {
// default Constructor + method
// constructors are kinda a method but without a return value (cannot do actions)
}
// method(parameter);
kingFishBread(String name) {
// parameter constructor + method
/* "method Overloading" = unlike C++,
multiple methods can use diff parameters with same name (kingFishBread) */
this.name = name;
// this.name calls upon the name inside the current class while using
// the name outside the class thats inputed
}
kingFishBread(String name, int calorie) {
// parameter constructor + method
this.name = name;
this.calorie = calorie;
}
void showCalorie() {
// method
System.out.println("This Bread calorie is" + this.calorie);
}
void whoMade() {
// method
}
}
public class Main { // main class
public static void main(String[] args) {
// main method
kingFishBread pizzaFishBread = new kingFishBread("PizzaFishBread", 500);
// pizzaFishBread = instance = made using kingFishBread = also class
kingFishBread creamFishBread = new kingFishBread("CreamFishBread");
pizzaFishBread.showCalorie();
creamFishBread.showCalorie();
}
}
/* INHERITANCE: when a class can use another class's stuff */
class parents {
int x, y, z;
void talk() {
System.out.println(x+ y+ z);
System.out.println("Im your father.");
}
}
class children extends parents {
int a, b, c;
void talk() { // same talk() as parents, "method overriding" + redefinition
// for parents, they use parents' talk() but for children, they use children's talk()
System.out.println("Im your son"); // sun
}
}
public class Main {
public static void main(String[] args) {
parents appa = new parents();
children son = new children();
appa.x = 10;
appa.y = 20;
appa.z = 30;
appa.talk();
son.talk();
}
}