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编程测试_类的使用的更多相关文章

  1. java编程思想-复用类总结

    今天继续读<java 编程思想>,读到了复用类一章,看到总结写的很好,现贴上来,给大家分享. 继承和组合都能从现有类型生成新类型.组合一般是将现有类型作为新类型底层实现的一部分来加以复用, ...

  2. JAVA编程中的类和对象

    1:初学JAVA,都知道JAVA是面向对象的编程.笔者这节开始说说类和对象.(实例仅供参考,如若复制粘贴记得修改包名和类名,避免出错) 学习JAVA的快捷键,Alt+/代码补全功能,其实此快捷键启动了 ...

  3. Java编程里的类和对象

    像我们搞计算机这块的,都知道这么一件事,当前的计算机编程语言主要分为两大块,一为面向过程,二为面向对象.Java就是一门纯面向对象的语言.学习了一个月左右的Java,在下对于Java当中的类和对象有了 ...

  4. java编程中Properties类的具体作用和使用

    如果不熟悉 java.util.Properties类,那么现在告诉您它是用来在一个文件中存储键-值对的,其中键和值是用等号分隔的.(如清单 1 所示).最近更新的java.util.Properti ...

  5. Java编程思想_笔记_第二章_一切都是对象

    第二章对于知识只是点到,会在以后章节会详细展开. 笔记的侧重会偏向记录自己知识模糊的地方.比如 xxx 很重要很难很实用,但是已经熟练使用就没有记录,而 “使用对象.成员名称来使用成员变量”,较简单而 ...

  6. java编程中Properties类的具体作用和使用!

    如果不熟悉 java.util.Properties类,那么现在告诉您它是用来在一个文件中存储键-值对的,其中键和值是用等号分隔的.(如清单 1 所示).最近更新的java.util.Properti ...

  7. java编程思想-复用类(2)

    如果java的基类拥有某个已被多次重载的方法名称,那么在导出类中重新定义该方法名称并不会屏蔽其在基类中的任何版本(这一点与C++不同) class Homer { char doh(char c) { ...

  8. java编程思想-复用类

    /* 一个文件中只能有一个public类 并且此public类必须与文件名相同 */ class WaterSource { private String s; WaterSource() { Sys ...

  9. Java 程序测试_循环语句中的break和continue

    package test; public class Loop_Statement { public static void main(String [] args) { String[] newba ...

随机推荐

  1. 菊花加载第三方--MBprogressHUD

    上次说到了网络请求AFN,那么我们在网络请求的时候,等待期间,为了让用户不认为是卡死或程序出错,一般都会放一个菊花加载,系统有一个菊花加载类叫UIProgressHUD.但是我今天要说的是一个替代它的 ...

  2. 一起学JUCE之Atomic

    Atomic功能是提供简单的类保持原始值,并且提供对其执行原子操作:Atomic是线程安全的,类型的实现比较简单,就是通过各种措施保证变量的操作达到原子操作,有一点需要注意Atomic使用的时候只支持 ...

  3. jsp发布后应用根目录

    1.发布到tomcat后获取应用的根目录 ServletContext s1=this.getServletContext(); String temp=s1.getRealPath("/& ...

  4. Tsinsen-1487:分配游戏【树状数组】

    首先一定要看到x + y + z = N这个条件,没看到就世界再见了. 赢的人得分需要大于等于2,那么无非就是 (x, y), (x, z), (y, z), (x, y, z) 大于其他的点.但是考 ...

  5. OI队内测试一【数论概率期望】

    版权声明:未经本人允许,擅自转载,一旦发现将严肃处理,情节严重者,将追究法律责任! 序:代码部分待更[因为在家写博客,代码保存在机房] 测试分数:110 本应分数:160 改完分数:200 T1: 题 ...

  6. Unity中使用扩展方法解决foreach导致的GC

    对于List这种顺序表,我们解决的时候还是可以使用for代替foreach即可.但是对于非顺序表,比如Dictionary或者Set之类,我们可以扩展方法Foreach,ForeachKey和Fore ...

  7. UVa 990 - Diving for Gold

    题目大意:一个潜水者去海底寻找金子,已知有n个有金子的地点,分别给出他们的深度和价值.但是由于潜水者只有一瓶氧气,所以他只能在海底呆有限的时间,问他如何才能在这有限的时间里获得尽可能多的金子,并打印出 ...

  8. React Native 之 HelloWorld

    1. 切换目录 输入之前要切换到要保存的目录 2. 修改下载源 cd ~/ vim .npmrc 添加 registry = https://registry.npm.taobao.org 3. 在终 ...

  9. 分布式cookie-session的实现(spring-session)

    分布式cookie-session的实现(spring-session) 本文使用的spring-session版本为 1.0.0,地址为: https://github.com/spring-pro ...

  10. spring mvc在Controller中获取ApplicationContext

    spring mvc在Controller中获取ApplicationContext web.xml中进行正常的beans.xml和spring-mvc.xml的配置: 需要在beans.xml中进行 ...