Вы находитесь на странице: 1из 5

Inheritance, Interfaces and Abstract Classes, Oh My! 1) What's wrong with me?

class Clock{ int minute; int hour; public Clock(int minute, int hour){ this.minute = minute; this.hour = hour; } } public class Cuckoo_Clock extends Clock{ public Cuckoo_Clock(int minute, int hour){ this.minute = minute; this.hour = hour; } public static void main(String[] args){ Cuckoo_Clock c = new Cuckoo_Clock(4, 3); } }

2) Whats the error?


class Bank{ private int balance; protected int bankID; public String bankName; public Bank(String name, int balance, int bankID){ this.balance = balance; this.bankID = bankID; this.bankName = name; } } public class BankBranch extends Bank{ public BankBranch(String name, int balance, int bankID){ super(name, balance, bankID); } public int getBalance(){ return balance; } public static void main(String[] args){ BankBranch b = new BankBranch("Chase", 54, 10282); System.out.println(b.getBalance()); } }

3) what methods must TrickInterfaces implement?


interface Edible { public Edible eat(int e); }

interface Cookable extends Edible{ public int cookTime(int e); public String dishName(int e); }

interface Compostable extends Edible{ public Edible compost(int c); } public class TrickInterfaces implements Cookable{ }

4)Whats the output for each line of main ? What are the static and dynamic types of all the object on each line of main?
class pipe{ int level = 1; public int carry(int b){ return b; } public int getLevel(){ return level; } } class tube extends pipe{ int level = 2; public int carry(int a){ return level + a; } public int getLevel(){ return level; } public int TubePressure(){ return 10282; } } public class Shadowing{ public static void main(String[] args){ tube t = new tube(); System.out.println(t.carry(10)); pipe p = (pipe)t; System.out.println(p.carry(10)); p.level = 50; System.out.println(p.carry(10)); System.out.println(p.level); System.out.println(p.getLevel()); } }

Вам также может понравиться