what would be the output?

Consider the following class:
public class IdentifyMyParts {
public static int x = 7;
public int y = 3;
}

a. How many class variables does the IdentifyMyParts class contain? What are their names?
b. How many instance variables does the IdentifyMyParts class contain? What are their names?

c. What is the output from the following code:

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);



Comments

  • [b][red]This message was edited by Vilanye at 2005-9-14 10:0:14[/red][/b][hr]
    : Consider the following class:
    : public class IdentifyMyParts {
    : public static int x = 7;
    : public int y = 3;
    : }
    :
    : a. How many class variables does the IdentifyMyParts class contain? What are their names?
    : b. How many instance variables does the IdentifyMyParts class contain? What are their names?
    :
    : c. What is the output from the following code:
    :
    : 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) You can't count? Should be pretty straightforward.

    b) Find out what an instance variable is. Basically what is the difference between a static variable and a non-static variable?

    c) Run it and find out. Put the code in part C in main, and IdentifyMyParts in a another file and give it the same name as the class name. If you don't understand the output trace it on paper and keep in mind what a static variable is. If you are still stuck, come back and ask specific questions about its behavior.

    Please don't post homework, expecting to be spoon-fed the answers. No one here will do your homework for you, and it will not help you.
    [italic][blue]Just my 2 bits[/blue][italic]



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion