COMP 274 COMP274 Week 2 Homework Assignment Solution

COMP 274 COMP274 Week 2 Homework Assignment Solution


  • $12.99

COMP 274 Week 2 Homework

1. Can you access an instance variable from a static method? Explain why or why not.

2. Can you access a static variable from an instance method? Explain why or why not

3. Consider the case where you have two classes, ClassA and ClassB, such that ClassA contains a member variable defined as ClassB myBobj. ClassB contains a constructor which takes a String parameter. ClassA provides a constructor which accepts a String parameter which is to be provided to myBobj. What needs to be done to initialize the ClassB member variable with the value from the ClassA constructor?

4. Here are some class definitions with questions that follow.

5. Give an example using Java syntax of how some class Y can be setup to inherit from some other class X.

6. What is a significant difference between C++ and Java inheritance?

7. How is the keyword super used? Give two different uses for it and include Java examples.

8. Explain the difference between public, private, and protected access specifiers. Give some guidelines of when each should be used

9. Explain what package access means and how it is specified.

10.  What can you do in Java to prevent a method from being overridden in a derived class? Give example code in your answer.

11. How do you prevent a class from being extended? Give example code in your answer.

12. Explain how dynamic binding works in Java.

We Also Recommend



Sold Out