码迷,mamicode.com
首页 > 编程语言 > 详细

java6

时间:2016-04-14 22:29:13      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:

interface ClassName{
public String getClassName();
}
class Company implements ClassName{
public String getClassName(){
return "Company";
}
}
public class per01{

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ClassName name =new Company();
System.out.print(name.getClassName());
}
}

 

技术分享

class Employer{
private String name;
private int age;
private char sex;
public Employer(){
}
public Employer(String name,int age,char sex){
super();
this.name=name;
this.age=age;
this.sex=sex;
}
public String toString(){
return "员工姓名:"+this.name+" 年龄:"+this.age+
" 性别:"+this.sex;
}
}
class Manager extends Employer{
private String job;
private double income;
public Manager(){
}
public Manager(String name,int age,char sex,String job,double income){
super(name,age,sex);
this.job=job;
this.income=income;
}
public String toString(){
return super.toString()+" 职位:"+this.job+" 年薪:"+this.income;
}
}
class Staff extends Employer{
private String dept;
private double salary;
public Staff(){
}
public Staff(String name,int age,char sex,String dept,double salary){
super(name,age,sex);
this.dept=dept;
this.salary=salary;
}
public String toString(){
return super.toString()+" 部门:"+this.dept+" 月薪:"+this.salary;
}
}
public class per03 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Employer ea=new Manager("张三",28,‘男‘,"员工",5000.0);
Employer eb=new Staff("李四",31,‘女‘,"员工",2000.0);
System.out.println(ea);
System.out.println(eb);
}
}

技术分享

abstract class Shape{
public abstract double area();
public abstract double perimeter();
}
class Juxing extends Shape{
private double wide;
private double longs;
public Juxing(){
}
public Juxing(double wide,double longs){
super();
this.wide=wide;
this.longs=longs;
}
public double area(){
return this.longs*this.wide;
}
public double perimeter(){
return (this.longs +this.wide)*2;
}
}
class Sanjiao extends Shape{
private double edgea;
private double edgeb;
private double edgec;
public Sanjiao(){
}
public Sanjiao(double edgea,double edgeb,double edgec){
super();
this.edgea=edgea;
this.edgeb=edgeb;
this.edgec=edgec;
}
public double area(){
return this.edgea*this.edgeb/2;
}
public double perimeter(){
return this.edgea+this.edgeb+this.edgec;
}
}
class Yuan extends Shape{
private double radius;
public Yuan(){
}
public Yuan(double radius){
super();
this.radius=radius;
}
public double area(){
return this.radius*this.radius*Math.PI;
}
public double preimeter(){
return this.radius*2*Math.PI;
}
@Override
public double perimeter() {
// TODO Auto-generated method stub
return 0;
}
}
public class per04 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Shape juxing=new Juxing(12.5,30.6);
Shape sanjiao=new Sanjiao(12.4,30.2,40.3);
Shape yuan=new Yuan(40.4);
System.out.println("矩形面积:"+juxing.area()+" 矩形周长:"+juxing.perimeter());
System.out.println("三角形面积:"+sanjiao.area()+" 三角形周长:"+sanjiao.perimeter());
System.out.println("圆形面积:"+yuan.area()+" 圆形周长:"+yuan.perimeter());
//System.out.println("椭圆面积:"+round.area()+" 椭圆周长:"+round.perimeter());
}

}//圆有点问题

 技术分享

java6

标签:

原文地址:http://www.cnblogs.com/zp742601689/p/5393192.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!