ICSE Class 10 Computer Applications Question 14 of 16

Encapsulation and Inheritance — Question 16

Back to all questions
16
Question

Question 16

Declare a public class CoolClass.

  1. Write the header for a public member method CoolMethodA.
  2. Write the header for an integer member method CoolMethodB that should be accessible to the classes in the package but not to derived classes.
  3. Write the header for an integer member method CoolMethodC that should be accessible only to other methods of the class.
  4. Write the header for a character member method CoolMethodD that should be accessible to the classes in the package and any derived classes.
Answer
public class CoolClass
{
    public void CoolMethodA()   {

    }

    int CoolMethodB()   {

    }

    private int CoolMethodC()   {

    }

    protected char CoolMethodD() {

    }
}