第7章 类和对象

Posted comicfuji

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第7章 类和对象相关的知识,希望对你有一定的参考价值。

7.1

package pra;
public class Pra1 {
	private String name;
	public String out() {
		return name;
	}
	public void input(String name) {
		this.name=name;
	}
	public static void main(String[] args) {
		Pra1 heav=new Pra1();
		heav.input("Chari");
		System.out.println(heav.out());
	}
}

7.2

package pra;
public class Pra1 {
	private double length;
	private double width;
	public Pra1(double length,double width){
		this.length=length;
		this.width=width;		
	}
	public double product() {
		return length*width;
	}
	
	public static void main(String[] args) {
		Pra1 rec=new Pra1(55.5,65.5);
		System.out.println(rec.product());	
	}
}

7.3

package pra;
public class Pra1 {
	public static void main(String[] args) {
		int i;
		for(i=0;i<args.length;i++) {
			System.out.println(i);
		}		
	}
}

以上是关于第7章 类和对象的主要内容,如果未能解决你的问题,请参考以下文章

第7章 类和对象

第1章 类和对象——定义类和创建对象

面向对象编程导论 An Introduction to Object-Oriented Programming

第8章 面向对象编程

第6章 泛型

20182311 2019-2020-1 《数据结构与面向对象程序设计》第7周学习总结