1.The Method Overloading
The method name is duplicate but the parameter is different in one same class.
2.The Constructor
How to establish an object of a class
characteristics:
The method name is duplicate but no return value
public class Car(){
public car();
}
The advantage of Constructor
1.Make the codes conciser.
2.There will be defined datas when used later.
Car c2 = new Car(4,3,4);
public class Car {
public int wheelCounts;
public int engines;
public int seats;
//The Method overloading & Constructor
// 1 The method overloading
public Car(){
}
// 2.the method overloading & constructor
public Car(int wCount,int countEngine,int countSeat){
wheelCounts = wCount;
engines = countEngine;
seats = countSeat;
}
public void test(){
System.out.println("The amount of engines:"+engines);
}
}
public class Myclass {
public static void main(String[] args) {
{
Car c1 = new Car();
c1.engines = 2;
c1.test();
//if the test() method is above the c1.engines
//There isn't any shows when use 'test();'
Car c2 = new Car(4,3,4);
c2.test();
//
}
}