package com.liu.test03; import java.io.Serializable; /** * @author : liu */ public class Person implements Serializable { //属性 private int age; public String name; //方法 private void eat(){ System.out.println("Person----->eat"); } public void sleep(){ System.out.println("Person----->sleep"); } }
package com.liu.test03; /** * @author : liu * 日期:14:27:02 * 描述:IntelliJ IDEA * 版本:1.0 */ //子类 @MyAnnotation("abc") public class Student extends Person implements MyInterface{ //属性 private int sno;//学号 double height;//身高 protected double weight;//体重 public double score;//成绩 @Override @MyAnnotation("helloMyMthod") public void myMethod() { System.out.println("我重写了myMethod方法"); } //方法 @MyAnnotation("三好学生") public String showInfo(){ return "我是一名三好学生"; } //重载方法 public String showInfo(int a,int b){ return "我是一名三好学生"; } private void work(){ System.out.println("我以后会找工作---》码农 程序员 程序猿 程序媛"); } void happy(){ System.out.println("做人最重要的就是开开心心"); } protected int getSno(){ return sno; } //构造器 public Student(){ } private Student(int sno){ this.sno=sno; } Student(int sno,double weight){ this.sno=sno; this.weight=weight; } protected Student(int sno , double weight,double height){ this.weight=weight; this.sno=sno; this.height=height; } @Override public String toString() { return "Student{" + "sno=" + sno + ", height=" + height + ", weight=" + weight + ", score=" + score + '}'; } }
package com.liu.test03; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import static java.lang.annotation.ElementType.*; import static java.lang.annotation.ElementType.LOCAL_VARIABLE; /** * @author : liu * 日期:09:16:44 * 描述:IntelliJ IDEA * 版本:1.0 */ /* * @Target:定义当前注解能够修饰程序中的那些元素 * @Retention定义注解的一个声明周期 * */ @Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE}) @Retention(RetentionPolicy.RUNTIME) public @interface MyAnnotation { String value();//属性 }
package com.liu.test03; /** * @author : liu * 日期:09:06:14 * 描述:IntelliJ IDEA * 版本:1.0 */ public interface MyInterface { //自定义接口,随便定义一个抽象方法: void myMethod(); }
标签:完善,weight,liu,补充,sno,void,int,public,上面 From: https://www.cnblogs.com/jeldp/p/16817940.html