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中類的一些知識點Java
- DIM中的一些知識點(慢更)
- Java SE中的一些基礎知識點截圖說明Java
- mysql的一些知識點MySql
- CGI的一些知識點
- Jquery的一些知識點jQuery
- 一些cookie的知識點Cookie
- java NIO和Concurrent包的一些知識點Java
- Java中IO流的知識點總結Java
- PLSQL一些常用的知識點SQL
- 雜湊的一些知識點
- 積累的一些程式碼片段/小知識
- Java知識點總結(動態執行JS程式碼 )JavaJS
- Java 介面,最少必要知識Java
- day1 java concurrent包一些知識點Java
- java小知識點Java
- Java與C/C++不同的一些基礎知識點JavaC++
- 關於AP的一些知識點
- vue的一些基礎知識點Vue
- RHCE考試的一些知識點
- Vue一些知識點總結Vue
- Python程式碼註釋的一些基礎知識Python
- 【JAVA】- 知識點小結Java
- Java 知識點總結Java
- Java 反射【前置知識點】Java反射
- java基礎知識點Java
- java知識點-高階Java
- java Web知識點(2)JavaWeb
- Java知識點總結Java
- Java知識點學習Java
- java知識點彙總Java
- java 重寫知識點Java
- java 多型知識點Java多型
- 關於網頁的一些小知識點網頁
- jQuery常用的一些知識點總結jQuery
- 一些關於IO流的知識點
- Core Java 的知識點總結Java
- 總結的Java知識點集合Java