Home > Java > javaTutorial > body text

Improve code reusability

大家讲道理
Release: 2016-11-09 10:25:39
Original
1783 people have browsed it

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();
         
    }
}
Copy after login
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template