// Dog.java
class Dog {
String name;
public Dog (String name) {
this.name = name
}
void speak(String str){
System.out.println(this.name+str);
}
}
public class Test {
public static void main(String[] args){
Dog dog = new Dog("jiaBa");
dog.speak("汪汪"); //
}
}
使用 javac Test.java 编译为 Test.class,
java Test 执行 Test.class
Thread Stack Heap Memory
Dog()
main
对象实例存放在堆中,内存中,结构是什么。
class Employee {
String name;
Integer salary;
Integer sales;
Integer bonus;
public Employee(String name, Integer salary, Integer sales) {
this.name = name;
this.salary = salary;
this.sales = sales;
}
}
public class Test {
static int BONUS_PERCENTAGE = 10;
static int getBonusPercentage(int salary) {
int percentage = salary * BONUS_PERCENTAGE / 100;
return percentage;
}
static int findEmployeeBonus(int salary, int noOfSales) {
int bonusPercentage = getBonusPercentage(salary);
int bonus = bonusPercentage * noOfSales;
return bonus;
}
public static void main(String[] args) {
Employee john = new Employee("John", 5000, 5);
john.bonus = findEmployeeBonus(john.salary, john.sales);
System.out.println(john.bonus);
}
}
重定向
var newUrl = map.get(window.loction);
if (newUrl !== null){
window.loction = newUrl
}