Object-Oriented Programming Revision PDF

Summary

This document contains multiple-choice questions focused on object-oriented programming (OOP) concepts, especially in the context of Java. It covers features of Java, and programming languages like machine language, assembly language, and high-level languages. The questions cover various topics, from fundamental concepts to more complex topics.

Full Transcript

Object Orientated Programming Multiple choice questions Revision Eclipse is a powerful, open-source IDE that provides robust support for Java and other object-oriented programming languages. By standardizing on Eclipse, we can: 1. Ensure Uniformity 2. Leverage Specific Features 3. F...

Object Orientated Programming Multiple choice questions Revision Eclipse is a powerful, open-source IDE that provides robust support for Java and other object-oriented programming languages. By standardizing on Eclipse, we can: 1. Ensure Uniformity 2. Leverage Specific Features 3. Facilitate Collaboration 4. All of the above © There are three main types of computer languages: 1. Machine Language 2. Assembly Language 3. High-Level Languages © Programming has progressed through various stages: Machine Code Assembly Language Machine-Independent Programming Languages Procedures & Functions Objects © Why is Java and Object-Oriented Programming important? A) Inheritance © B) Cloning Objects C) Code Reusability © D) Duplicate Characteristics What are the features of Java? (Select all that apply): Object-Oriented Interpreted Portable Secure Dynamic Reliable Multithreaded All of the above © What do classes include? A) Attributes only B) Methods that perform tasks C) Methods that return information after task completion D) Both B and C © What translates a computer program written in one language into another language? A) Compiler © B) Interpreter C) Translator D) None of the above The set of legal structures and commands that can be used in a particular programming language is called: A) Semantics B) Syntax © C) Grammar D) Lexicon A problem in the structure of a program that causes the compiler to fail is called: A) Logic error B) Runtime error C) Syntax error © D) Hardware error A sequence of text characters that can be printed or manipulated in a program is called a: A) String © B) Character array C) Literal D) Stream Which of the following correctly matches escape characters in Java? A) \t - Backslash character B) \n - New line character © C) \" - Tab character D) \\ - Quotation mark Every variable has: A) A name B) A type C) A size and a value D) All of the above © An object in Java is a collection of: A) Fields (object state) B) Methods (behaviors) C) Static variables only D) Both A and B © Which of the following is true about objects in Java? A) Objects do not maintain their own state. B) Each object has its own memory for fields but shares the same code with other objects of the same type. © C) Each object has unique code and shared state. D) Objects cannot maintain state. Which of the following are benefits of modern Object-Oriented Programming (OOP)? A) Code re-use B) Encapsulation C) Inheritance D) Polymorphism E) All of the above © Constructors in Java are: A) A type of method used to construct objects. © B) Used to modify the value of class attributes. C) Automatically invoked to destroy objects. D) Always private and cannot be called by other classes. What does the private keyword in Java mean? A) No class can access the private member. B) Only methods in the same package can access the private member. C) The private member can be accessed by any method in the class that contains it. © D) It makes the member accessible to any class in any package. The method getMessage() is an accessor method. Which of the following is true? A) It modifies the value of its associated attribute. B) It returns the value of its associated attribute. © C) It does not have a return type. D) It accepts a formal argument matching the attribute’s type. The method setMessage() is a mutator method. Which of the following is true? A) It returns the value of its associated attribute. B) It has no return type and changes the value of its associated attribute. © C) It accepts no arguments. D) It is always private. What does the public keyword signify for a class, data, or method in Java? A) The class, data, or method is visible only to classes within the same package. B) The class, data, or method is visible to any class in any package. © C) The class, data, or method is visible only to the declaring class. D) The class, data, or method is visible only to methods inside the class. Which of the following is true about inner classes in Java? A) An outer class can access the private members of an inner class. B) An inner class can access the public members of the outer class. © C) An inner class can be accessed directly outside the outer class. D) An outer class cannot access the public members of an inner class. When should you use enum types in Java? A) When you need to represent a fixed set of constants. © B) When you need to store random values. C) When you want to define complex data structures. D) When you need to store a list of objects with varying data types. What is called when an instance of one class is used as a reference in another class? A) Object inheritance B) Object aggregation © C) Object composition D) Object manipulation Which of the following best describes the relationship between a superclass and a subclass? A) A subclass inherits behavior from its superclass and can override its methods. © B) A subclass cannot inherit from a superclass. C) A subclass cannot access the members of its superclass. D) A superclass extends the subclass. Which of the following statements is true regarding method overriding in Java? A) A private method in the superclass can be overridden in the subclass. B) A static method in the superclass can be overridden in the subclass. C) A method can be overridden only if it is accessible in the subclass.(c) D) A private method in the subclass can be overridden in its superclass. Which statement is true about static methods and inheritance in Java? A) Static methods can be overridden in the subclass. B) Static methods are inherited but cannot be hidden. C) Static methods, when redefined in the subclass, hide the method from the superclass. © D) Static methods are not inherited by subclasses. What is the fundamental difference between method overriding and method overloading? A) Overloading involves changing the return type, while overriding changes method behavior. B) Overloading occurs when two methods in the same class have the same name but different parameters, while overriding involves modifying inherited methods. © C) Overloading and overriding are the same. D) Overloading is only possible in the superclass, while overriding is only possible in the subclass. What does the garbage collector in Java do? A) It reclaims memory from objects that no longer have a reference pointing to them. © B) It prevents memory leaks by cleaning up memory automatically. C) It manually frees memory that is no longer needed. D) It checks for infinite loops in the program. What triggers garbage collection in Java? A) When memory usage exceeds a threshold. B) When there are no valid references to an object. © C) When System.gc() is invoked. D) When an object’s finalize() method is called. Which of the following statements is true about the garbage collector in Java? A) It runs periodically as a background thread. © B) It must be manually invoked using System.gc(). C) It deletes all objects in memory when invoked. D) It is not included in Java. Which of the following is true about the finalize() method in Java? A) It requires parameters to be executed. B) It returns a value when invoked. C) It is defined in the java.lang.Object class and returns void. © D) It is automatically called by the JVM without the need for garbage collection. Which of the following is true about arrays in Java? A) Arrays are primitive data types. B) Arrays are objects that occupy memory. © C) Arrays do not support initializer lists. D) Arrays cannot hold objects. How can a histogram be used to display array data graphically? A) By plotting each numeric value as a bar of asterisks (*). © B) By listing the numeric values in a table format. C) By drawing lines between data points. D) By converting array values to strings. Which of the following is true about overloaded constructors in Java? A) Overloaded constructors must have the same parameter list. B) Overloaded constructors are defined in different classes. C) Overloaded constructors can have the same name but must have different parameter lists. © D) Overloaded constructors must always be private. What is object aggregation in Java? A) Creating multiple objects of the same class. B) Creating an instance of one class as a reference in another class. © C) Merging multiple classes into one. D) Overloading a constructor in multiple classes. What is the correct description of a superclass and a subclass in Java? A) A subclass defines methods, while a superclass implements them. B) A subclass inherits data fields and methods from its superclass. © C) A superclass always extends the subclass. D) A subclass and superclass cannot coexist in the same package. Which statement is true about method overriding in Java? A) Any method can be overridden, regardless of access modifiers. B) A private method can be overridden in a subclass. C) A static method can override an instance method. D) A method can only be overridden if it is accessible in the subclass. © Which of the following is true about the java.lang.Object class? A) It is the base class for all Java objects. © B) It must be manually imported into every Java program. C) It cannot be overridden in any subclass. D) It is only used for garbage collection. What is the purpose of upcasting and downcasting in Java? A) To convert primitive data types B) To create objects of abstract classes C) To build complicated programs using simple syntax and enable polymorphism © D) To make methods static What does Polymorphism in Java allow us to do? A) Perform multiple actions simultaneously B) Perform a single action in different ways © C) Perform multiple actions sequentially D) Increase the performance of the code Which of the following are the two types of polymorphism in Java? A) Compile-time and Runtime © B) Abstract-time and Real-time C) Method-time and Constructor-time D) Object-time and Class-time Which statement about abstract classes in Java is correct? A) Abstract classes can be instantiated directly. B) Abstract classes are used to define objects that will never be instantiated. © C) Abstract classes can have both concrete and abstract methods. D) Abstract classes cannot have any methods. What is the primary purpose of abstract classes in Java? A) To define methods that are only used once B) To define classes that will be used as superclasses in inheritance hierarchies © C) To instantiate objects directly D) To perform mathematical calculations Can a subclass of an abstract class be instantiated? A) No, abstract classes cannot have subclasses B) Yes, but only if all abstract methods in the subclass are implemented © C) Yes, but only if the abstract class is concrete D) No, a subclass of an abstract class cannot be instantiated

Use Quizgecko on...
Browser
Browser