View Single Post
  #2 (permalink)  
Old 12-06-2007, 10:56 PM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
All user-defined interfaces are subtypes of the type Interface.
Interfaces
Using an Interface as a Type
A method call is sent to an object and the method of the actual type is executed.
Defining Methods
A data model specifies the user interface.
Models are usually designed to function independently of user interfaces.
If classes B and C are subclasses of A, then any state variable of A is also a state variable of B and C.
Controlling Access to Members of a Class
Code:
public class InheritanceTest { public static void main(String[] args) { A a = new A(); System.out.println("a = " + a); B b = new B(); System.out.println("b = " + b); C c = new C(); System.out.println("c = " + c); } } class A { public String fieldOne = "field one"; protected String fieldTwo = "field two"; private String fieldThree = "field three"; String fieldFour = "field four"; public String toString() { String s = getClass().getName(); return s + "[fieldOne:" + fieldOne + " fieldTwo:" + fieldTwo + " fieldThree:" + fieldThree + " fieldFour:" + fieldFour + "]"; } } class B extends A { public String toString() { return "B[fieldOne:" + fieldOne + " fieldTwo:" + fieldTwo + // " fieldThree:" + fieldThree + " fieldFour:" + fieldFour + "]"; } } class C extends A { public String toString() { return super.toString(); } }
Reply With Quote