美文网首页
Java notes

Java notes

作者: 饥人谷__文轩 | 来源:发表于2018-02-15 11:51 被阅读0次

lecture 4

Animal foo = new Dog(); // ok

override heiachy

dog[] is animal[]

final no sub class

String is final

Dog dog = new Animal() // cannot go up
Dog dog = new GoldenRetriver // ok
GoldenRetriver cc = new Dog() // no
Goldenretriver goldenrever = (Goldenretrive) dog // depends on if dog is GoldenRetriver

Abstract class

super

invoke super constructor

 public class Cat extends Animal {
      @Override protected String makeNoise(){
      
  }
}
  • attempt to assign weaker access privileges' was public (cannot override it in animal)
@Override public String makeNoise(){
    return "meow"
}

Abstract

 public abstract class Animal{
   public abstract String makeNoise();
}

Abstract class you might not need the implementation

Object class

getClass()  
 // returns the Class class instance
hashcode()  
// a hash code value for this object
private final String name
@Override public boolean equals(Object obj) {
      if (this == obj) {
          return true;
      }
      if ((obj == null ) || (getClass() != obj.getClass()) {
         return false;
      }
      // for every propery under consideration for equality, check  
        Dog that = (Dog) obj
       return (nam ==  null ? that.name == null : name.equals(that.name));
}
@Override public int hashCode() {
      int result = this.id == null ? 0 : id.hashCode();
      result = 31 (prime number) * result + (dateTime == null ? 0 : dateTime.hashCode());
      return result;
      //return (this.name == null ? 0 : this.name.hashCode());
}

if equals gethashCode must be the same

相关文章

  • JAVA学习

    参考https://cyc2018.github.io/CS-Notes/#/notes/Java%20%E5%9...

  • 多线程

    java并发,java内存模型,java锁https://github.com/CyC2018/CS-Notes/...

  • Java notes

    lecture 4 Animal foo = new Dog(); // ok override heiachy ...

  • Notes: Java

    函数式借口可以自定义 创建时要确定: 加上 @FunctionalInterface 注解 只能有一个抽象方法。 ...

  • Java Notes

    Java Collections Framework 计算机专业的应该知道,本专业最核心的一门课是数据结构与算法。...

  • Java Notes

    程序段: Package Import Public Class Other Class 如何声明常量: fina...

  • 为什么要有虚拟内存?

    github:https://github.com/AriseFX/java-notes[https://gith...

  • Android高级目录及网络大神的笔记

    网络大神笔记:https://github.com/BlackZhangJX/Android-Notes java...

  • Java Basic Notes

    JVM, JRE, and JDK Java Virtual Machine是Java虚拟机,Java程序需要运行...

  • Java Concurrency Notes

    Process for JVM to Run a Program JVM(Java Virtual Machine...

网友评论

      本文标题:Java notes

      本文链接:https://www.haomeiwen.com/subject/jrwytftx.html