Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Questions
Question 1: Consider the following class:public class IdentifyMyParts { public static int x = 7; public int y = 3; }Question 1a. How many class variables does the IdentifyMyParts class contain? What are their names?
Answer 1a: 1, xQuestion 1b. How many instance variables does the IdentifyMyParts class contain? What are their names?
Answer 1b: 1, yQuestion 1c. What is the output from the following code:
Answer 1c: Here is the output:IdentifyMyParts a = new IdentifyMyParts(); IdentifyMyParts b = new IdentifyMyParts(); a.y = 5; b.y = 6; a.x = 1; b.x = 2; System.out.println("a.y = " + a.y); System.out.println("b.y = " + b.y); System.out.println("a.x = " + a.x); System.out.println("b.x = " + b.x);a.y = 5 b.y = 6 a.x = 2 b.x = 2
Exercises
Exercise 1: Write a class whose instances represent a single playing card from a deck of cards. Playing cards have two distinguishing properties: rank and suit. Be sure to keep your solution as you will be asked to rewrite it in Enumerated Types.
Answer 1: Card.javaExercise 2: Write a class whose instances represents a full deck of cards. You should also keep this solution.
Answer 2: See Deck.java .Exercise 3: Write a small program to test your deck and card classes. The program can be as simple as creating a deck of cards and displaying its cards.
Answer 3: See DisplayDeck.java .
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.