Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-06-2007, 04:24 PM
Member
 
Join Date: Dec 2007
Posts: 4
ldb88 is on a distinguished road
A few questions about Java and design
T/F and an explanation if not T please

1. All user-defined interfaces are subtypes of the type Interface.
2. A method call is sent to an object and the method of the actual type is executed.
3. A data model specifies the user interface.
4. If classes B and C are subclasses of A, then any state variable of A is also a state variable of B and C.

I looked in the JavaDocs at Sun, but couldn't find a type Interface anywhere, but I think I remember hearing something about it. I think you have to use dispatching for #2, and #3 I really have no clue. For #4, does the visibility matter, or is it a state variable in B and C even if it was declared private in A?

Thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-06-2007, 09:56 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,189
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(); } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-06-2007, 10:45 PM
Member
 
Join Date: Dec 2007
Posts: 4
ldb88 is on a distinguished road
Ok.
1. I didn't find anything on this.
2. This should be true, right?
3. This one would be false.
4. B and C cannot directly access it, so it would not be considered a state
variable, right? So false?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-06-2007, 11:09 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,189
hardwired is on a distinguished road
Language semantics is the problem here. I don't know where/how you are learning java.
If I answered these from my (limited) point of view/language I would say:
1. All user-defined interfaces are subtypes of the type Interface.
Awkward way of asking. Probably, yes.
2. A method call is sent to an object and the method of the actual type is executed.
Strictly speaking, no. But probably yes. The jvm selects the method according to its name, return type and the number and type of arguments.
3. A data model specifies the user interface.
Agreed: false.
4. If classes B and C are subclasses of A, then any state variable of A is also a state variable of B and C.
A "state" variable is generally considered a member or instance variable in class scope. Subclasses can access public, protected and package-private (from within the package) variables of a superclass but not private variables. I tried to show this in the test app.
So, generally speaking, yes, except for private variables. Access of *any* variable in the superclass, no.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 12-07-2007, 01:51 AM
Member
 
Join Date: Dec 2007
Posts: 4
ldb88 is on a distinguished road
Alright, I think I've got it. Thanks!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
The Strategy Design Pattern in Java(II) JavaForums Java Blogs 0 03-14-2008 01:00 PM
The Strategy Design Pattern in Java(I) JavaForums Java Blogs 0 03-14-2008 01:00 PM
2 simple java questions jimJohnson New To Java 2 02-02-2008 10:35 AM
www.javaadvice.com - The one stop resource for all your Java questions and answers JAdmin Reviews / Advertising 0 01-24-2008 08:53 PM
few java questions hiaslpix New To Java 4 01-01-2008 06:47 AM


All times are GMT +3. The time now is 10:30 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org