fundamental of java programming coursera week 3 quiz answers
OOPS - Practice Quiz
1. What is the main difference between Object-Oriented Programming (OOPs), Functional Programming, and Procedural Programming?
- OOPs focuses on objects and classes, while Functional Programming focuses on functions and immutability, and Procedural Programming focuses on procedures and routines.
- OOPs is only used in Java, while Functional Programming and Procedural Programming are used in other programming languages.
- OOPs uses inheritance, while Functional Programming and Procedural Programming do not.
- OOPs is a deprecated programming paradigm, while Functional Programming and Procedural Programming are widely used.
2. What are classes and objects in Java?
- Classes are instances of objects.
- Objects are instances of classes.
- Classes and objects are the same thing in Java.
- Classes and objects are not used in Java.
3. What are access modifiers in Java?
- Keywords used to define mathematical operations in Java.
- Keywords used to define the visibility and accessibility of class members (variables, methods, inner classes) in Java.
- Keywords used to define the data types in Java.
- Keywords used to define loops and conditional statements in Java.
4. What is a wrapper class in Java?
- A class that wraps objects and provides access to their methods and properties.
- A class that provides utility methods for working with arrays.
- A class that provides access to input/output operations.
- A class that provides methods for encryption and decryption of data.
5. What is the purpose of the "this" keyword in Java?
- To refer to the current instance of the class within a method or constructor.
- To create a new instance of a class.
- To refer to the parent class in case of inheritance.
- To specify the return type of a method.
Constructors - Practice Quiz
6. What is a constructor in Java?
- A method used to copy the values of one object to another.
- A method used to define the behavior of an object.
- A special method used to create and initialize objects of a class.
- A method used to define the properties of an object.
7. What is a copy constructor in Java?
- A constructor used to create a deep copy of an object.
- A constructor used to create a shallow copy of an object.
- A constructor used to create a new object from an existing object.
- A constructor used to create an object from a different class.
8. What is constructor chaining in Java?
- A way to chain multiple constructors together to create a complex object.
- A way to call a constructor of a different class.
- A process where one constructor calls another constructor of the same class using “this” keyword.
- A way to create a constructor with multiple parameters.
9. What is the purpose of a private constructor in Java?
- To prevent instantiation of the class.
- To allow multiple instances of the class.
- To make the class accessible from any package.
- To enable inheritance of the class.
10. What is a singleton class in Java?
- A class that can have multiple instances.
- A class that can have only one instance throughout the lifetimeof an application.
- A class that cannot have any instance.
- A class that can be instantiated from any package.
Inheritance - Practice Quiz
11. What is inheritance in Java?
- A way to create objects of a class.
- A mechanism to hide the implementation details of a class.
- A process of creating a new class by inheriting properties and methods from an existing class.
- A technique to access variables and methods of an object.
12. What is multiple inheritance in Java?
- The ability of a class to inherit from multiple classes at the same time.
- The ability of a class to inherit from a single class only.
- The ability of a class to inherit from any number of classes.
- The ability of a class to inherit from abstract classes only.
13. What is polymorphism in Java?
- The ability of a class to have multiple constructors.
- The ability of a class to have multiple methods with the same name but different parameters.
- The ability of objects of different classes to respond to the same method call.
- The ability of a class to inherit properties and methods from another class.
14. What is dynamic method dispatch or runtime polymorphism in Java?
- The ability of a class to have multiple constructors.
- The ability of a class to have multiple methods with the same name but different parameters.
- The ability of objects of different classes to respond to the same method call.
- The ability of a method in a subclass to override a method in its superclass and get invoked at runtime based on the actual object type.
15. What is the main difference between inheritance in C++ and Java?
- C++ supports multiple inheritance, while Java does not.
- Java supports multiple inheritance, while C++ does not.
- C++ supports polymorphism, while Java does not.
- Java supports polymorphism, while C++ does not.
Overloading and Overriding - Practice Quiz
16. What is method overloading in Java?
- The ability of a class to have multiple methods with the same name but different return types.
- The ability of a class to have multiple methods with the same name and same parameter list.
- The ability of a class to override methods from its superclass.
- The ability of a class to have multiple methods with the same name but different parameter lists.
17. Which of the following is a way to achieve method overloading in Java?
- Using the same method name and the same parameter list in multiple classes in a hierarchy.
- Using the same method name and the same parameter list in a single class.
- Using the same method name and the same return type in a single class.
- Using the same method name but different parameter lists in a single class.
18. What is method overriding in Java?
- The ability to have multiple methods with the same name in a single class.
- The ability to inherit methods from multiple classes at the same time.
- The ability to create new methods in a subclass that have the same name as methods in the superclass.
- The ability to provide a new implementation of a method in a subclass that overrides the implementation in the superclass.
19. What is the difference between method overloading and method overriding in Java?
- Method overloading is based on the same method name but different parameter lists in a single class, while method overriding is based on the same method name and the same parameter list in multiple classes in a hierarchy.
- Method overloading is based on the same method name but different parameter lists in a single class, while method overriding is based on the same method name and the same parameter list in a single class.
- Method overloading is the ability to provide a new implementation of a method in a subclass that overrides the implementation in the superclass, while method overriding is the ability to have multiple methods with the same name in a single class.
- Method overloading is based on the same method name but different parameter lists in a single class, while method overriding is the ability to provide a new implementation of a method in a subclass that overrides the implementation in the superclass.
20. What are the different ways of achieving method overloading in Java?
- By providing multiple methods with the same name and same parameter list in a single class.
- By providing multiple methods with the same name but different return types in a single class.
- By providing multiple methods with the same name but different parameter lists in a single class.
- By providing multiple methods with the same name and same parameter list in different classes of a hierarchy.
OOPS and Other Essential Concepts - Graded Quiz
21. Which of the following statements about abstraction in Java is correct?
- Abstraction is the process of hiding implementation details and exposing only the essential features of an object.
- Abstraction is the process of converting an object into a different data type.
- Abstraction is the process of making an object immutable.
- Abstraction is the process of converting a primitive data type into an object.
22. Which of the following is true about abstract classes in Java?
- Abstract classes can be instantiated.
- Abstract classes can have both abstract and concrete (implemented) methods.
- Abstract classes cannot have any constructors.
- Abstract classes can be used to create objects.
23. Which of the following statements is true about encapsulation in Java?
- Encapsulation is the process of converting an object into a different data type.
- Encapsulation is the process of hiding implementation details and exposing only the essential features of an object.
- Encapsulation is the process of making an object immutable.
- Encapsulation is the process of converting a primitive data type into an object.
24. Which of the following is true about abstract classes and interfaces in Java?
- Abstract classes can have constructor implementations, while interfaces cannot.
- Interfaces can have concrete (implemented) methods, while abstract classes cannot.
- Abstract classes can extend multiple classes, while interfaces can only extend one interface.
- Abstract classes can provide multiple inheritance, while interfaces cannot.
25. Which of the following statements is true about the difference between abstract classes and interfaces in Java?
- Abstract classes can be implemented by any class, while interfaces can only be extended by other interfaces.
- Abstract classes can provide multiple inheritance, while interfaces cannot.
- Abstract classes can only have abstract methods, while interfaces can have both abstract and non-abstract methods.
- Abstract classes can have multiple inheritance, while interfaces can only have single inheritance.
26. Which of the following statements is true about abstract classes and interfaces in Java?
- Abstract classes can have method implementations, while interfaces can only have method declarations.
- Abstract classes can be fully implemented, while interfaces cannot.
- Abstract classes can have fields and variables, while interfaces can only have constants.
- Abstract classes can be used to achieve multiple inheritance, while interfaces cannot.
27. Which of the following statements is true about abstract classes in Java?
- Abstract classes can be instantiated directly.
- Abstract classes cannot have any constructors.
- Abstract classes can have both abstract and concrete methods.
- Abstract classes can be used to create objects.
28. Which of the following is not a valid modifier for an interface in Java?
- public
- private
- static
29. What is the distinction between abstract classes and interfaces in Java?
- Abstract classes can provide multiple inheritance, while interfaces cannot.
- Abstract classes can have method implementations, while interfaces can only have method declarations.
- Interfaces can be implemented by any class, while abstract classes can only be subclassed.
- Abstract classes can have private methods, while interfaces cannot.
30. Which of the following statements is true about abstract methods in Java?
- Abstract methods have a body and can be directly invoked.
- Abstract methods do not have a body and must be implemented by any concrete class that extends the abstract class or implements the interface.
- Abstract methods can have method implementations.
- Abstract methods can only be used in abstract classes, not in interfaces.
31. Which statement accurately describes abstract classes in Java?
- Abstract classes cannot have any constructors.
- Abstract classes can be instantiated directly.
- Abstract classes can have instance variables and static variables.
- Abstract classes cannot have any methods.
32. Which of the following statements is true about interfaces in Java?
- Interfaces can have instance variables.
- Interfaces can have constructors.
- Interfaces can have default and static methods implementations.
33. Differentiating between abstract classes and interfaces in Java: Which of the following statements is true?
- Abstract classes can be used to achieve multiple inheritance, while interfaces cannot.
- Abstract classes can have method implementations, while interfaces can only have method declarations.
- Abstract classes can have fields and variables, while interfaces can only have constants.
- Abstract classes can provide partial implementation of methods, while interfaces cannot.
34. Which of the following statements is true?
- Encapsulation is the process of making all class members public for easy access.
- Encapsulation is the process of making all class members private for better encapsulation.
- Encapsulation is the process of hiding implementation details and exposing only the essential features of a class.
- Encapsulation is the process of creating objects from classes.
35. Can you identify the accurate statement regarding abstract classes and interfaces in Java?
- Abstract classes can have multiple inheritance, while interfaces cannot.
- Abstract classes can have multiple abstract methods, while interfaces can have only one abstract method.
- Abstract classes cannot have any variables, while interfaces can have variables.
- Abstract classes can have constructor, while interfaces cannot have constructors.
36. Please select the correct statement regarding abstract classes and interfaces in Java.
- Abstract classes can be used to achieve full implementation of methods, while interfaces can only have method declarations.
- Abstract classes can have instance variables and static variables, while interfaces can only have constants.
- Abstract classes can have multiple inheritance, while interfaces cannot.
- Abstract classes can be implemented by multiple classes, while interfaces can be extended by multiple interfaces.
37. Can you identify the true statement about abstract classes in Java?
- Abstract classes can be instantiated directly.
- Abstract classes cannot have any constructors.
- Abstract classes can have abstract methods as well as concrete methods.
- Abstract classes can have multiple inheritance.
38. Could you point out the accurate statement regarding interfaces in Java?
- Interfaces can have private methods.
- Interfaces can have instance variables.
- Interfaces can have constructors.
- Interfaces can be implemented by multiple classes.
39. Which of the following statements correctly describes encapsulation in Java?
- Encapsulation is the process of making all class members private for better encapsulation.
- Encapsulation is the process of hiding implementation details and exposing only the essential features of a class.
- Encapsulation is a way to achieve multiple inheritance in Java.
- Encapsulation allows direct instantiation of objects from a class.