dog类java代码 java狗类
java 写dog类
public class Dog {
成都创新互联公司是一家专业提供东阳企业网站建设,专注与网站设计制作、成都做网站、H5技术、小程序制作等业务。10年已为东阳众多企业、政府机构等服务。创新互联专业网站建设公司优惠进行中。
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("请输入要设置的年龄:");
jack.setAge(new Scanner(System.in).nextInt());
System.out.println("请输入要设置的体重:");
jack.setWeight(new Scanner(System.in).nextInt());
System.out.println("修改后年龄为:" + jack.getAge() + "体重为:"
+ jack.getWeight());
}
}
java作业求助
按照题目要求编写的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类,它有名字(name)颜色(color)和年龄(age)三个属性
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是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程。
Java具有简单性、面向对象、分布式、健壮性、安全性、平台独立与可移植性、多线程、动态性等特点。Java可以编写桌面应用程序、Web应用程序、分布式系统和嵌入式系统应用程序等。
网页题目:dog类java代码 java狗类
文章起源:http://hbruida.cn/article/ddcepgo.html