public?class?Dog?{
成都創(chuàng)新互聯(lián)公司是一家專業(yè)提供東陽企業(yè)網(wǎng)站建設(shè),專注與網(wǎng)站設(shè)計(jì)制作、成都做網(wǎng)站、H5技術(shù)、小程序制作等業(yè)務(wù)。10年已為東陽眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站建設(shè)公司優(yōu)惠進(jìn)行中。
int?age;
int?weight;
public?int?getAge()?{
return?age;
}
public?void?setAge(int?age)?{
this.age?=?age;
}
public?int?getWeight()?{
return?weight;
}
public?void?setWeight(int?weight)?{
this.weight?=?weight;
}
public?Dog(int?age,?int?weight)?{
super();
this.age?=?age;
this.weight?=?weight;
}
@SuppressWarnings("resource")
public?static?void?main(String[]?args)?{
Dog?jack?=?new?Dog(2,?10);
System.out.println("年齡為:"?+?jack.getAge()?+?"體重為:"?+?jack.getWeight());
System.out.println("請輸入要設(shè)置的年齡:");
jack.setAge(new?Scanner(System.in).nextInt());
System.out.println("請輸入要設(shè)置的體重:");
jack.setWeight(new?Scanner(System.in).nextInt());
System.out.println("修改后年齡為:"?+?jack.getAge()?+?"體重為:"
+?jack.getWeight());
}
}
按照題目要求編寫的Java程序如下.
class Dog{
private String name;
private int age;
private String color;
public Dog(){}
public Dog(String name,int age,String color){
this.name=name;
this.age=age;
this.color=color;
}
public void bark(){
System.out.println("汪汪");
}
}
public class Main{
public static void main(String[] args){
Dog d=new Dog("花花",3,"白色");
d.bark();
}
}
Dog.javapublic class Dog { private String name; private String color; private int age; public
Dog() { } public Dog(String name, String color, int age) { this.name = name; this.color =
color; this.age = age; } public void show() { System.out.println("name:" + this.name);
System.out.println("color:" + this.color); System.out.println("age:" + this.age); }}
DogTest.javapublic class DogTest { public static void main(String[] args) { Dog dog1 = new Dog("大黑", "黑", 2); Dog dog2 = new Dog("小白", "白", 1); dog1.show(); dog2.show(); }}// try...
Java是一門面向?qū)ο缶幊陶Z言,不僅吸收了C++語言的各種優(yōu)點(diǎn),還摒棄了C++里難以理解的多繼承、指針等概念,因此Java語言具有功能強(qiáng)大和簡單易用兩個(gè)特征。Java語言作為靜態(tài)面向?qū)ο缶幊陶Z言的代表,極好地實(shí)現(xiàn)了面向?qū)ο罄碚摚试S程序員以優(yōu)雅的思維方式進(jìn)行復(fù)雜的編程。
Java具有簡單性、面向?qū)ο?、分布式、健壯性、安全性、平臺(tái)獨(dú)立與可移植性、多線程、動(dòng)態(tài)性等特點(diǎn)。Java可以編寫桌面應(yīng)用程序、Web應(yīng)用程序、分布式系統(tǒng)和嵌入式系統(tǒng)應(yīng)用程序等。