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. iOS开发实现Label中多颜色多字体

     UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(8, 100, 300, 30)]; label.textColor = wor ...

  2. iOS调用另一个程序

    在 iOS 里,程序之间都是相互隔离,目前并没有一个有效的方式来做程序间通信,幸好 iOS 程序可以很方便的注册自己的 URL Scheme,这样就可以通过打开特定 URL 的方式来传递参数给另外一个 ...

  3. thinkPHP的学习

    1.版本,以3.1为主,因为手册是基于这个的,最新的版本,还没有对应的手册 2.发现一个问题,echo 中文时,出现乱码,而调用模版则正常. 3.写url的注意大小写.index和Index是不同的 ...

  4. python 爬取的数据要如何展现(可视化)?

    我是把数据放在 mongodb ,然后单独一个脚本作分析,导出 json ,用 c3.js 画图,然后随便写个很简单的页面就好了. 展示在这里: http://107.170.207.236/job_ ...

  5. PCA主成分分析方法

    PCA: Principal Components Analysis,主成分分析. 1.引入 在对任何训练集进行分类和回归处理之前,我们首先都需要提取原始数据的特征,然后将提取出的特征数据输入到相应的 ...

  6. Android自定义控件之TextView

    转自:http://labs.easymobi.cn/?p=284 有时候Android自带的控件无法满足我们的某些要求,这时就需要我们自定义控件来实现这些功能.比如需要一个TextView里的字倾斜 ...

  7. Xcode 之 snippet 代码重用

    1. 选中代码 2. 拖入xcode 右下侧的 snippet 区域 3. 修改名称 4. 修改快捷输入 (shortcut) 5. <#content#> ,可选修改项

  8. 【腾讯Bugly干货分享】你为什么需要 Kotlin

    本文来自于腾讯Bugly公众号(weixinBugly),未经作者同意,请勿转载,原文地址:http://mp.weixin.qq.com/s/xAFKGarHhfQ3nKUwPDlWwQ 一.往事 ...

  9. iOS 添加导航栏两侧按钮

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"首页" style ...

  10. Struts2的拦截器----Dog实例

    拦截器是一个类,这个类包含方法,用来解决DRY规则,即代码复用的问题.如果不调用拦截器,代码中需要显示通过代码调用目标方法,定义了拦截器,系统就会自动执行.大部分时候,拦截器方法都是通过代理的方式调用 ...