Description of this paper

Computer Programming




Can you access an instance variable from a static method? Explain why or why not.;Can you access a static variable from an instance method? Explain why or why not.;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?;Here are some class definitions with questions that follow.;public class BaseClass { // methods of BaseClass };public SomeClass extends BaseClass;{ // methods of SomeClass };a. SomeClass scobj = new SomeClass();b. BaseClass bcobj = scobj;c. SomeClass scobj2 = bcobj;d. bcobj.aMethodOfSomeClass(), // does not exist in BaseClass;A. Is statement b above legal, or is casting required?;B. Statement c is trying to assign the SomeClass object referred to by bcobj to a SomeClass reference variable scobj2. What is wrong with this statement and how would you fix it.;C. In statement d, a BaseClass reference is trying to access a SomeClass class method that is not part of BaseClass. Is this legal? Explain.;Give an example using Java syntax of how some class Y can be setup to inherit from some other class X.;What is a significant difference between C++ and Java inheritance?;How is the keyword super used? Give two different uses for it and include Java examples.;Explain the difference between public, private, and protected access specifiers. Give some guidelines of when each should be used.;Explain what package access means and how it is specified.;What can you do in Java to prevent a method from being overridden in a derived class? Give example code in your answer.;How do you prevent a class from being extended? Give example code in your answer.;Explain how dynamic binding works in Java.


Paper#68359 | Written in 18-Jul-2015

Price : $22