Home >Java >javaTutorial >Improve code reusability

Improve code reusability

大家讲道理
大家讲道理Original
2016-11-09 10:25:391802browse

Improve code reusability

package car;
 
public class Car {
    String color;
    int number;
     
    void run(){
        System.out.println(color+"::"+number);
    }
}
 
class carDemo
{
    public static void main(String[] args)
    {
        Car c = new Car();
     
        show(c);
    }
    /*
     * 封装功能
     * Car c = new Car();
     * Car c1 = new Car();
     * */
    public static void show(Car cc)
    {
        cc.color = "red";
        cc.number = 4;
        cc.run();
         
    }
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn