java中的介面一些知識點———— 程式碼
一 ;
nterface Shape {
public abstract void draw();
// default public void func(){
//
// }
}
class Cycle implements Shape{
public void draw(){
System.out.println(" ⭕");
}
}
class Flower implements Shape{
public void draw(){
System.out.println(" ❀");
}
}
public class TestLong {
public static void drawMap(Shape shape){
shape.draw();
}
public static void main (String[] args){
Shape shape = new Flower();
shape.draw();
Shape shape1 = new Cycle();
shape1.draw();
Flower flower = new Flower();
drawMap(flower);
}
}
二;
interface IA{
void func();
}
abstract class A implements IA{
public void fun(){
System.out.println(“4444”);
}
}
interface IB extends IA{
void fun2();
}
class C implements IB{
public C() {
super();
}
@Override
public void func() {
}
@Override
public void fun2() {
}
}
interface ID{
public void fun3();
}
interface IC extends IB ,ID{
@Override
void func();
@Override
void fun2();
@Override
void fun3();
}
class Animal {
protected String name ;
public Animal (String name){
this.name = name;
}
}
interface IFlying{
void fly();
}
interface IRunnig {
void run();
}
interface ISwimming{
void swim();
}
class Cat extends Animal implements IRunnig {
public Cat(String name) {
super(name);
}
@Override
public void run() {
System.out.println(this.name + " 正在跑");
}
}
class Fish extends Animal implements ISwimming{
public Fish(String name){
super(name);
}
@Override
public void swim() {
System.out.println(this.name + " 正在用尾巴游泳");
}
}
class Forg extends Animal implements IRunnig, ISwimming{
public Forg(String name){
super(name);
}
@Override
public void swim() {
System.out.println(this.name + " 正在游泳" );
}
@Override
public void run() {
System.out.println(this.name + " 正在跑步");
}
}
class RoBot implements IRunnig{
@Override
public void run() {
System.out.println(“機器人再跑”);
}
}
public class TestDemo {
public static void function1(IRunnig iRunnig){
iRunnig.run();
}
public static void function2(ISwimming iSwimming) {
iSwimming.swim();
}
public static void function3(IFlying iFlying){
iFlying.fly();
}
public static void main (String[] args){
function2(new Fish(“HAHHAHA”));
}
public static void main1 (String[] args){
Animal animal = new Fish("HAHHAHA");
ISwimming iSwimming = new Fish("HHHHHHHH");
}
}
三 ;
class Student implements Comparable{
public int age;
public String name;
public int score;
public Student(int age, String name, int score) { // alt + insert
this.age = age;
this.name = name;
this.score = score;
}
@Override
public String toString() {
return "Student{" +
"age=" + age +
", name='" + name + '\'' +
", score=" + score +
'}';
}
@Override
public int compareTo(Student o) {
if (this.age < o.age){
return -1;
}else if(this.age > o.age){
return 1;
}else {
return 0;
}
}
}
public class TestCheng {
public static void main3 (String[] args){
Student student1 = new Student(10,“lallal”,65);
Student student2 = new Student(34,“laal”,63);
if (student1.compareTo(student2) > 0){
System.out.println("student1 > student2");
}else if(student1.compareTo(student2) < 0){
System.out.println("student1 < student2");
}else {
System.out.println("student1 == student2");
}
}
public static void main (String[] args){
Student[] students = new Student[3];
students[0] = new Student(10,"lallal",65);
students[1] = new Student(34,"laal",63);
students[2] = new Student(20,"lal",85);
System.out.println(Arrays.toString(students));
Arrays.sort(students);
System.out.println(Arrays.toString(students));
}
public static void main1 (String[] args){
int[] array = {1,2,3,3,4,2,4,35,45,4};
Arrays.sort(array);
System.out.println(Arrays.toString(array));
}
}
四;
class Money implements Cloneable{
public double money = 34.5;
@Override
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
}
class Person implements Cloneable{
public String name = " lalal";
public Money m = new Money();
@Override
public String toString() {
return "Person{" +
"name='" + name + '\'' +
'}';
}
@Override
protected Object clone() throws CloneNotSupportedException {
Person person = (Person) super .clone();
person.m = (Money) person.m.clone();
return person;
//return super.clone();
}
}
public class TestXi {
public static void main (String[] args)throws CloneNotSupportedException {
Person person = new Person();
Person person1 = (Person) person.clone();
System.out.println(person.m.money);
System.out.println(person1.m.money);
System.out.println("============");
person1.m.money = 99.99;
System.out.println(person.m.money);
System.out.println(person1.m.money);
}
}
相關文章
- java NIO和Concurrent包的一些知識點Java
- DIM中的一些知識點(慢更)
- mysql的一些知識點MySql
- 一些cookie的知識點Cookie
- day1 java concurrent包一些知識點Java
- Java知識點總結(動態執行JS程式碼 )JavaJS
- PLSQL一些常用的知識點SQL
- Java中IO流的知識點總結Java
- Java 介面,最少必要知識Java
- Python程式碼註釋的一些基礎知識Python
- 關於AP的一些知識點
- vue的一些基礎知識點Vue
- java小知識點Java
- jQuery常用的一些知識點總結jQuery
- 關於網頁的一些小知識點網頁
- hadoop的一些知識點 配置步驟Hadoop
- 關於Async、Await的一些知識點AI
- python3 numpy的一些小知識點Python
- 一些關於IO流的知識點
- Vue一些知識點總結Vue
- 總結的Java知識點集合Java
- Core Java 的知識點總結Java
- Java 知識點總結Java
- java知識點-高階Java
- 【JAVA】- 知識點小結Java
- java 重寫知識點Java
- java 多型知識點Java多型
- Java 反射【前置知識點】Java反射
- java基礎知識點Java
- 關於 API介面的一些知識分享API
- Java基礎知識整理之程式碼塊Java
- 一些點雲的小知識,從官方文件中發現的例子
- 一些有點奇怪的知識(持續更新)
- web開發知識體系中必要的知識點Web
- 【Java】容器相關知識點Java
- 2018.03.12、Android知識點-Java篇AndroidJava
- Java基礎知識點梳理Java
- java 多型知識點2Java多型