abstract class Animal { ... public abstract void speak(); }Will the following definition of Tiger compile without error?
class Tiger extends Animal { public void scratch() {;} public String getName() { return "tigger"; } }
String n = Tiger.getName();make sense and compile properly?
class Tiger extends Animal { ... private void speak() { System.out.println("roar!"); } }
Animal a = ... ; Dog d = ... ; Cat c = ... ; a = d; a = (Animal)d; d = a; d = (Dog)a; c = d; d = c;
Bag b = ...; b.insert("some string"); b.insert(3); b.insert("3");given the following:
class Bag { ... public void insert(String s) {...} public void insert(int i) {...} public void insert(float f) {...} }
class Human { String name; ... public String getName() { return name; } public String getInfo() { return getName(); } } class Student extends Human { String ID; ... public String getName() { return name+":"+ID; } } ... Student s = new Student("Madonna","111-22-3333"); Human h = s;
Airplane a = ...; Bird b = ...; FlyingSquirrel s = ...; CanFly f; f = a; f = b; f = s; f = (CanFly)s; a = b;Assume the following definitions:
interface CanFly { public void fly(); } class Airplane implements CanFly { public void fly() {...} } class Bird implements CanFly { public void fly() {...} } class FlyingSquirrel { public void fly() {...} }
class Point { int x,y; public void reset() { x = 0; y = 0; } }
class Employee { String ID; static String companyName; static public void setCompanyName(String n) { companyName = n; } public void getID() { return ID; } ... }Could getID() refer to method setCompanyName()? Could setCompanyName() refer to getID()? Is the following class method definition equivalent/valid to the above definition?
static public void setCompanyName(String n) { this.companyName = n; }