4.15 JAVA

Source: Internet
Author: User

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.) {
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", "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 (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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.