Java编程测试_类的使用
package test; class A
{
private static int i; // Static, Private Attribute
private static int j; // Static, Private Attribute
private static int cnt = 0; // Statistic the number of the object
void set(int a , int b) // Set the value by the function in class
{ // The security can be guaranteed
i = a;
j = b;
} public A(int a , int b) // Construction Method
{
System.out.printf("The function has been called!\n");
i = a;
j = b;
cnt++;
} public static int Cnt() //Get the number of the object in this class
{ //It should can be static because we can
return cnt; //A.Cnt
} public void show() // A Show Method in the class
{
System.out.printf("The value in this object: i=%d,j=%d\n",i,j);
} } ///////////Extends/////////////////////
class Human
{
public String name = "Mike";
public int age = 22;
} class Student extends Human
{
public double score = 90;
} class Graduate extends Student
{
public String tutor = "Jay";
}
/*************Extends**********************/ public class TestMemo { static int add(int a ,int b) // The reentry of a function
{
return (a+b);
} static int add(int a ,int b , int c) // The reentry of a function
{
return (a+b+c);
} static double add(double a ,double b) // The reentry of a function
{
return a+b;
}
public static void main(String[] args) // The reentry of a function
{
A aa = new A(66,88);
// aa.i = 100;
// aa.j = 20;
//aa.set(50, 67);
aa.show();
System.out.printf("Two int value be plused:%d\n",add(2,8));
System.out.printf("Three int value be plused:%d\n",add(1,2,3));
System.out.printf("Two float value be plused:%f\n",add(1.9,2.0));
A bb = new A(12,10); //change the value in the class by another object
aa.show(); // because of the static attribute
System.out.printf("The vaule count in A class: %d\n",A.Cnt());
Graduate stu = new Graduate();
System.out.printf("Test of EXTENDS: %s's tutor is %s\n",stu.name,stu.tutor);
System.out.printf("Test of EXTENDS: %s's age is %d\n",stu.name,stu.age);
}
}
Java编程测试_类的使用的更多相关文章
- java编程思想-复用类总结
今天继续读<java 编程思想>,读到了复用类一章,看到总结写的很好,现贴上来,给大家分享. 继承和组合都能从现有类型生成新类型.组合一般是将现有类型作为新类型底层实现的一部分来加以复用, ...
- JAVA编程中的类和对象
1:初学JAVA,都知道JAVA是面向对象的编程.笔者这节开始说说类和对象.(实例仅供参考,如若复制粘贴记得修改包名和类名,避免出错) 学习JAVA的快捷键,Alt+/代码补全功能,其实此快捷键启动了 ...
- Java编程里的类和对象
像我们搞计算机这块的,都知道这么一件事,当前的计算机编程语言主要分为两大块,一为面向过程,二为面向对象.Java就是一门纯面向对象的语言.学习了一个月左右的Java,在下对于Java当中的类和对象有了 ...
- java编程中Properties类的具体作用和使用
如果不熟悉 java.util.Properties类,那么现在告诉您它是用来在一个文件中存储键-值对的,其中键和值是用等号分隔的.(如清单 1 所示).最近更新的java.util.Properti ...
- Java编程思想_笔记_第二章_一切都是对象
第二章对于知识只是点到,会在以后章节会详细展开. 笔记的侧重会偏向记录自己知识模糊的地方.比如 xxx 很重要很难很实用,但是已经熟练使用就没有记录,而 “使用对象.成员名称来使用成员变量”,较简单而 ...
- java编程中Properties类的具体作用和使用!
如果不熟悉 java.util.Properties类,那么现在告诉您它是用来在一个文件中存储键-值对的,其中键和值是用等号分隔的.(如清单 1 所示).最近更新的java.util.Properti ...
- java编程思想-复用类(2)
如果java的基类拥有某个已被多次重载的方法名称,那么在导出类中重新定义该方法名称并不会屏蔽其在基类中的任何版本(这一点与C++不同) class Homer { char doh(char c) { ...
- java编程思想-复用类
/* 一个文件中只能有一个public类 并且此public类必须与文件名相同 */ class WaterSource { private String s; WaterSource() { Sys ...
- Java 程序测试_循环语句中的break和continue
package test; public class Loop_Statement { public static void main(String [] args) { String[] newba ...
随机推荐
- mysql中TPS, QPS 的计算方式
今天突然有个同事问题一个问题, mysqlTPS和QPS的计算公式是什么? 以前确实也没有关注过这个计算公式,所以查了下学习了下: 下面是参考内容. 在做db基准测试的时候,qps,tps 是衡量数 ...
- 浅析IoC框架
今日拜读了一篇关于IOC的文章,特意转载,和大家分享一下 1 IoC理论的背景 我们都知道,在采用面向对象方法设计的软件系统中,它的底层实现都是由N个对象组成的,所有的对象通过彼此的合作,最终实 ...
- Android与JNI(二) ---- Java调用C++ 动态调用
目录: 1. 简介 2. JNI 组件的入口函数 3. 使用 registerNativeMethods 方法 4. 测试 5. JNI 帮助方法 6. 参考资料 1. 简介 Android与JNI( ...
- sqlserver 笔记:常用字符串函数
select tid,tid+ coalesce(tid0,'101') from article where id=1 ---如果tid为null 则 返回101 select LEN('你 ...
- JS 中 Class - 类创建
Class - 类创建 Class类实现了在JavaScript中声明一个新的类, 并通过构造函数实例化这个类的机制.通过使用Class.create()方法, 你实际上声明了一个新的类, 并定义了一 ...
- 基于 Python 和 Scikit-Learn 的机器学习介绍
Reference:http://mp.weixin.qq.com/s?src=3×tamp=1474985436&ver=1&signature=at24GKibw ...
- Nodejs之package.json介绍说明
规范的package.json及package.json中各属性的作用. "name":包名. "description":包简介. "author& ...
- 扫码JSP
扫码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.o ...
- ios 清除列表选中状态
[tableView deselectRowAtIndexPath:indexPath animated:YES];
- 堡垒机--paramiko模块
做堡垒机之前,来了解一下paramiko模块. 实际上底层封装的SSH. SSHclient(1) import paramiko #实例化一个ssh ssh = paramiko.SSHClient ...