02 2018 档案
摘要:1 package cn.xlf.oop.abstractClass; 2 3 public abstract class Animal { 4 public abstract void run();//抽象方法只能在抽象中 5 public void breath(){//抽象类中可以定义普通方法 6 System.out.pri...
阅读全文
摘要:1 package cn.xlf.oop.encapsulation01; 2 3 /** 4 * @author ZBG34854 5 * 6 */ 7 public class Man { 8 public String getId() { 9 return id; 10 } 11 public void se...
阅读全文
摘要:继承:类是对对象的抽象,继承是对某一批类的抽象对象 提高代码的复用性 extend 的意思的是扩展。 子类是父类的扩展。 子类继承父类,就可以得到父类的全部属性和方法(除了父类的构造方法) java 中只有单继承 没有多继承 一个类只能有一个直接父类。 对比原代码 方法的重写 用super语句调父类
阅读全文
摘要:1 package cn.xlf.test; 2 3 /** 4 * 测试重载 5 * @author ZBG34854 6 * 7 */ 8 public class TestOverlode { 9 public static void main(String[] args){ 10 MyMath m = new MyMath(); 11 ...
阅读全文
摘要:package cn.xlf.test; public class Point { double x,y,z; public Point(double _x,double _y,double _z){ x = _x; y = _y; z = _z; } //设置X,Y,Z的值 public void setX(double _x){ x = _x; ...
阅读全文
摘要:面向对象的本质 --以类的方式组织代码,以对象的方式组织(封装)数据
阅读全文
摘要:1 import java.util.Scanner;//scanner 是包含在Java.util中的;使用的时候需要调用 2 3 /** 4 * 测试Scanner类的使用、如何接受键盘的输入 5 * @author ZBG34854 6 * 7 */ 8 public class TestScanner { 9 public static void te...
阅读全文
摘要:1 /** 2 * 测试递归算法 3 * 4 * 5 */ 6 public class TestRecursion { 7 static int a = 0; 8 public static void test01(){ 9 a++; 10 if(a<=10){ 11 System.out.pr...
阅读全文
摘要:设计方法的原则:方法的本意是功能块,就是实现某个功能的语句块的集合。我们设计方法的时候,最好保持方法的原子性,就是一个方法只完成一个功能,这样利于我们后期的扩展。 1 //测试方法 2 public class TestMethod { 3 //设计方法的原则:方法的本意是功能块,就是实现某个功能的语句块的集合。我们设计方法的时候,最好保持方法的原子性,就是一个方法只完成一个功能,...
阅读全文
摘要:1 //比较break和continue语句的不同 2 public class TestBreakContinue { 3 public static void main(String[] args){ 4 int a = 0; 5 System.out.println("Begin"); 6 while(true){ 7 ...
阅读全文
摘要:1 /*测试for 2 * 用while和for循环输出1-1000之间能被5整除的数,且每行输出3个。 3 */ 4 public class TestFor { 5 public static void main(String[] args){ 6 for(int i = 1;i<=1000;i++){ 7 if(i%5==...
阅读全文
摘要:1 //jdk7.0中switch可以使用字符串做条件 2 public class TestSwitch02 { 3 public static void main(String[] args){ 4 String a = "向良峰"; 5 6 switch(a){//JDK 7的新特性,表达式可
阅读全文
摘要:1 //反向利用case穿透 2 public class TestSwitch { 3 public static void main(String[] args){ 4 char c = 'a'; 5 int rand =(int) (26*Math.random()); 6 char c2 =
阅读全文
摘要:1 //测试if语句 2 public class TestIf { 3 public static void main(String[] args){ 4 double d = Math.random();//0~1之间的小数 5 int e = (int)(d*5); //[0,4] 6 //i
阅读全文

浙公网安备 33010602011771号