superclass - Java getClass and super classes -
public boolean equals(object o) { if (this == o) return true; if ((o == null) || (this.getclass() != o.getclass())) return false; else { alunote umaluno = (alunote) o; return(this.nomeempresa.equals(umaluno.getnomeempresa()) && super.equals(umaluno); } }
could explain me how fourth line ((this.getclass() != o.getclass())
) works when argument super class? because classes have different names. this.getclass
return different name o.getclass
, right?
check following code snippet answers question. object o can hold object. o.getclass() return run time class of object
public class main { void method(object o) { system.out.println(this.getclass() == o.getclass()); } public static void main(string[] args) { new main().method(new object()); // false new main().method(new main()); // true new main().method(new string()); // false new main().method(new mainone()); // false } } class mainone extends main { }
Comments
Post a Comment