In: Computer Science
Which of the following is a motivation for passing functions around in Java?
Select one:
a. Compiled code with anonymous functions is smaller in size than with explicit functions.
(INCORRECT)b. Passing functions as objects around and applying them is significantly less complex than writing the logic for those algorithms directly.
c. It is the only way for the class to allow clients to access data that is otherwise private.
d. It allows clients to provide an algorithm without ownership of the data it operates on.
If we define a class as follows: public class Foo<T extends Bar> { }
Which of the following is a fact that we know about T? Select all that apply.
Select one or more:
a. Foo must define the same methods as Bar.
(INCORRECT)b. T must be a direct subclass of Bar.
c. T objects have access to all of the public methods defined in Bar.
d. T must be Bar or a class that inherits from Bar, directly or indirectly.
Which of the following is an advantage to using an interface as opposed to an abstract class?
Select one:
a. An interface can be the type for a variable declaration.
(INCORRECT)b. A class can inherit a default implementation for a method from an interface.
c. A class can implement multiple interfaces.
d. Interfaces can hold instance variables.
1) Which of the following is a motivation for passing functions around in Java?
Select one:
a. Compiled code with anonymous functions is smaller in size than with explicit functions.
b. Passing functions as objects around and applying them is significantly less complex than writing the logic for those algorithms directly.
c. It is the only way for the class to allow clients to access data that is otherwise private.
d. It allows clients to provide an algorithm without ownership of the data it operates on
--> Option a is correct as passing anonymous functions (lambda expressions) as lamba expressions do no genarate class file which reducs the compiled code and also optimizes the performance.
---------------------------------------------------------------------------------------------------------------------------------------------------
2) If we define a class as follows: public class Foo<T extends Bar> { }
Which of the following is a fact that we know about T? Select all that apply.
Select one or more:
a. Foo must define the same methods as Bar.
b. T must be a direct subclass of Bar.
c. T objects have access to all of the public methods defined in Bar.
d. T must be Bar or a class that inherits from Bar, directly or indirectly.
--> c, d options are correct here. As T is extending Bar class, T is subclass of Bar and it can be direct or indirect and T objects are able to access its super class methods.
--------------------------------------------------------------------------------------------------------------------------------------------------
3) Which of the following is an advantage to using an interface as opposed to an abstract class?
Select one:
a. An interface can be the type for a variable declaration.
b. A class can inherit a default implementation for a method from an interface.
c. A class can implement multiple interfaces.
d. Interfaces can hold instance variables.
--> option c is correct. In java we cannot extend multiple classes into same class, but we can achieve this multiple inheritence only through interfaces by implementing multiple interfaces.
---------------------------------------------------------------------------------------------------------------------------------------------------
If you have any queries, you can always reach out to me through comment section.