java inheritance keyword super()

Posted by gucciv12 on Stack Overflow See other posts from Stack Overflow or by gucciv12
Published on 2012-10-26T10:59:14Z Indexed on 2012/10/26 11:00 UTC
Read the original article Hit count: 1636

Filed under:
|
|

requirement:

Given the class 'ReadOnly' with the following behavior:

  • A (protected) integer instance variable named 'val'.

  • A constructor that accepts an integer and assigns the value of the parameter to the instance variable 'val'.

  • A method name 'getVal' that returns the value of 'val'.

    Write a subclass named 'ReadWrite' with the following additional behavior: Any necessary constructors.

  • a method named 'setVal' that accepts an integer parameter and assigns it the the 'val' instance variable.

  • a method 'isDirty' that returns true if the setVal method was used to override the value of the 'val' variable.

Code

class ReadWrite extends ReadOnly {
 super(int val);    
   void setVal(int val){this.val = val;}
     boolean isDirty() {if (setVal()(return true)) else return false;}}

More Hints:

  • ?     You should be using: modified
  • ?     You should be using: private
  • ?     You should be using: public

© Stack Overflow or respective owner

Related posts about java

Related posts about inheritance