0% found this document useful (0 votes)
123 views5 pages

Inheritance, Interfaces and Abstract Classes, Oh My! 1) What's Wrong With Me?

1) The Cuckoo_Clock class extends the Clock class but does not add any new functionality. 2) The BankBranch class gets a compile error because it tries to access the private balance field from the parent Bank class. 3) The TrickInterfaces class must implement the eat(), cookTime(), and dishName() methods defined in the Cookable interface. 4) The output would be: 10282, 10, 50, 50, 1. The static type is tube for the first line, pipe for lines 2-3, and pipe for lines 4-5. The dynamic type is always tube.

Uploaded by

gh269
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
123 views5 pages

Inheritance, Interfaces and Abstract Classes, Oh My! 1) What's Wrong With Me?

1) The Cuckoo_Clock class extends the Clock class but does not add any new functionality. 2) The BankBranch class gets a compile error because it tries to access the private balance field from the parent Bank class. 3) The TrickInterfaces class must implement the eat(), cookTime(), and dishName() methods defined in the Cookable interface. 4) The output would be: 10282, 10, 50, 50, 1. The static type is tube for the first line, pipe for lines 2-3, and pipe for lines 4-5. The dynamic type is always tube.

Uploaded by

gh269
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 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()); } }

You might also like