You are on page 1of 9

Inheritance

Quiz

GV Phi Loan

Y nghia cua lp Note


public class Note { private String noteName; private Note(String noteName) { this.noteName = noteName; } public String toString() { return noteName; } public static final Note MIDDLE_C = new Note("Middle C"), C_SHARP = new Note("C Sharp"), B_FLAT = new Note("B Flat"); }
GV Phi Loan

Y nghia cua lp Note


y la lp enumeration co 1 s i tng hng nh MIDDLE_C, SHARP_C,.. Khng th tao thm bt ky i tng nao t lp nay vi constructor la private

GV Phi Loan

Bai tp 1
Create a base class with only a nondefault constructor, and a derived class with both a default (no-arg) and nondefault constructor. In the derived-class constructors, call the base-class constructor

GV Phi Loan

Bai tp 1

GV Phi Loan

Bai tp 2

Output??

GV Phi Loan

Bai tp 2
Kt qua la:

GV Phi Loan

Bai tp 3

Output????
GV Phi Loan

Private f()
8

Bai tp 3
Vi f() cua lp cha PrivateOverride la private nn bi hidden i vi lp con Derived. Phng thc private cua lp cha khng th bi override trong lp con c.

f() cua lp con c xem nh 1 phng thc mi.

GV Phi Loan

You might also like