Answer to Question #279114 in Java | JSP | JSF for htp

Question #279114

Develop the following class execute and discuss the answer: Please note that each class stored in separate files. Write down the answer.

class SuperB {

   int x;

   void setIt (int n) { x=n;}

   void increase () { x=x+1;}

   void triple () {x=x*3;};

   int returnIt () {return x;}

}

class SubC extends SuperB {

   void triple () {x=x+3;} // override existing method

   void quadruple () {x=x*4;} // new method

}

public class TestInheritance {

   public static void main(String[] args) {

       SuperB b = new SuperB();

       b.setIt(2);

       b.increase();

       b.triple();

       System.out.println( b.returnIt() );

       SubC c = new SubC();

       c.setIt(2);

       c.increase();

       c.triple();

       System.out.println( c.returnIt() ); }

}



1
Expert's answer
2021-12-14T01:15:40-0500

The answer is 6 and 9.


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog