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

4.15 JAVA

时间:2016-04-15 13:57:30      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

interface ClassName{
String getClassName();
}


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

public class Test6_1{
public static void main(String[] args){
System.out.println(new Company().getClassName());
}
}

技术分享

 

abstract class Employee{
private String name;
private int age;
private String sex;

public Employee(){}
public Employee(String name,int age,String sex){
this.setName(name);
this.setAge(age);
this.setSex(sex);
}

public void setName(String name){
this.name = name;
}
public void setAge(int age){
this.age = age;
}
public void setSex(String sex){
this.sex = sex;
}

public String getInfo(){
return "name = "+this.name+
"; age = "+this.age+
"; sex = "+this.sex;
}
public abstract void print();
}

class Managemen extends Employee{
private String position;
private int annualPay;

public Managemen(){}
public Managemen(String name,int age,String sex){
super(name,age,sex);
}
public Managemen(String name,int age,String sex,String position,int annualPay){
super(name,age,sex);
this.setPosition(position);
this.setAnnualPay(annualPay);
}

public void setPosition(String position){
this.position = position;
}
public void setAnnualPay(int annualPay){
this.annualPay = annualPay;
}

public String getInfo(){
return super.getInfo()+
"; position = "+this.position+
"; annualPay = "+this.annualPay;
}
public void print(){
System.out.println(this.getInfo());
}
}

public class Test6_4{
public static void main(String[] aegs){
Managemen mgm = new Managemen("zjx",20,"man","Boss",10000000);
mgm.print();
}
}

技术分享

 

public interface Shape {

public double area();
public double perimeter();
}

public class Circle implements Shape {
double r = 5;
double pi = 3.14;

public double area() {
return pi*r*r;
}

public double perimeter() {
return 2*pi*r;
}

}


public class Rectangle implements Shape {
double a = 3;
double b = 4;

public double area() {
return a*b;
}

public double perimeter() {
return 2*(a+b);
}

}

public class Triangle implements Shape {
double a = 4;

public double area() {
return a*a;
}

public double perimeter() {
return 4*a;
}

}
public class Test6_5 {

public static void main(String[] args) {
Shape s1 = new Circle();
System.out.println(s1.area());
System.out.println(s1.perimeter());

Shape s2 = new Rectangle();
System.out.println(s2.area());
System.out.println(s2.perimeter());

Shape s3 = new Triangle();
System.out.println(s3.area());
System.out.println(s3.perimeter());
}

}

4.15 JAVA

标签:

原文地址:http://www.cnblogs.com/Godxi/p/5395057.html

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