java继承简例

面向对象程序设计 

封装 
继承
多态 

在类的声明中,需要定义类的名称,对该类的访问权限和该类的其他类的关系
类的声明格式如下:
   【修饰符】class  类名【extends 父类名】implements 接口列表{
}


修饰符:public  private abstract   final  

把类装进包里,在开头声明包的名字即可 
package com.wgh 
public  class Cric{
  final float PI =3.1415f;
 public void draw(){
     System.out.println(“this is a test programming!”)
}

}

继承:
public  class Animal{

   public Boolean live =true;
  public  String skin =” “;
  pubic  void eat(){
   System.out.println(“he can eat !”);
}
  public void move (){
  System.out.println(“he can move”);
}

}


public  class  Brid extends Aminal{

 public String skin=”羽毛”;
public void move(){
    System.out.println(“he can fly”);  //覆盖了父类的成员方法
}

}

Java中用接口来解决多重继承的问题

1.定义了两个接口

package goodjob;

public interface Caulate {
	final float PI = 3.14159f;
	float getArea(float r);
	float getCircu(float r);
	void draw();
	

}



package goodjob;

public interface GeometryShape {
   final float PI = 3.1415926f;
   float getArea(float r);
   float getCircu(float r);
   void draw();
   
   
}

2 然后在类中继承两个接口,逗号隔开:  public class Test  implements Caulate,GeometryShape 
/**
 * 
 */
package goodjob;

/**
 * @author Mr.Lv
 *
 */
public class Test  implements Caulate,GeometryShape{
	
	      
		public float getArea(float r){
			
			float area = Caulate.PI*r*r;
			return area;	
		}
		
		public float getCircu(float r){
			
			float Cir = 2*Caulate.PI*r;
			return Cir;
			
		}
		public void draw(){
			
			System.out.println("画一个同心圆!");
			
		}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
      Test test = new Test();  // Test test;
      float r = 7;
      float  area=test.getArea(r);
      float  Cir=test.getCircu(r);
      System.out.println("圆的面积为:"+area);
      System.out.println("圆的周长为:"+Cir);
      System.out.println("圆的面积为:"+test.getArea(8));
      test.draw();
	}

}

Console:
圆的面积为:153.93791
圆的周长为:43.98226
圆的面积为:201.06177
画一个同心圆!


集合  
Colllection  
List:  ArrayList   LinkedList
Set:   HashSet     TreeSet
Map: HashMap  

捕捉异常:
printStackTrace():方法输出异常的详细描述信息  

try{
代码块1;
}catch(Exception e){
      e.printStackTrace();    
}

线程:
开启:start()\
挂起: sleep()/join()/wait()_

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值