Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Java question (https://www.askmehelpdesk.com/showthread.php?t=772472)

  • Oct 23, 2013, 05:57 PM
    nomasana
    Java question
    Consider the following two class code:
    Public class MyClass {
    Protected int data1 = 0;
    Private char data2 = 0;

    Public MyClass(int x) {
    Data1= x;
    Data2 = data1 + 1;
    }

    Public getData2() {
    Return data2;
    }

    Public void doWork() {
    System.out.println(“In doWork of MyClass”);
    }
    }

    Public class YourClass extends MyClass {
    Private int data3 = 0;

    Public YourClass(int x) {
    Super(x);
    Data3 = x + 2;
    }

    Public void doWork() {
    System.out.println(“In doWork of YourClass”);
    }
    }

    Suppose we have the following code:
    MyClass m;
    YourClass y;
    M = MyClass(1);
    Y = YourClass(2);
    M.doWork();
    Y.doWork();
    M = y;
    M.doWork();

    I) (5 points) Show the all the class attribute values of the two objects (m and y), after the objects get instantiated (be careful).


    ii) (5 points) What gets printed when the code snippet is executed.
  • Oct 23, 2013, 08:48 PM
    ma0641
    This is the second JAVA homework or test question. Why are you taking the class without trying to learn? We do not answer these types of questions.

  • All times are GMT -7. The time now is 03:18 PM.