Introduction to OOP

RefinedBowenite avatar
RefinedBowenite
·
·
Download

Start Quiz

Study Flashcards

Questions and Answers

Which programming paradigm is focused on functions and splitting bigger tasks into smaller ones?

Procedural Programming

What is the primary focus of Object Oriented Programming?

Encapsulation

Which principle of Object Oriented Programming allows code and data to be accessed via well-defined interfaces?

Encapsulation

Which programming concept allows a single function to calculate the area for different shapes?

<p>Polymorphism</p> Signup and view all the answers

Which of the following statements about constructors in Java is correct?

<p>Constructors have the same name as the class</p> Signup and view all the answers

What happens if a class does not have a defined constructor?

<p>Java creates a default constructor</p> Signup and view all the answers

Which of the following is true about object initialization in Java?

<p>Object initialization can be done using a constructor</p> Signup and view all the answers

Which type of nested class in Java has access to other members of the enclosing class, even if they are declared private?

<p>Inner class</p> Signup and view all the answers

Which keyword is used in Java to call the superclass' constructor?

<p>super</p> Signup and view all the answers

In Java, can a subclass access the private members of its superclass?

<p>No</p> Signup and view all the answers

What is the order in which constructors for classes in a multilevel hierarchy are called?

<p>From top to bottom</p> Signup and view all the answers

Which one of these is true about the JRE (Java Runtime Environment)?

<p>JRE is used by end users to run Java programs</p> Signup and view all the answers

What is the difference between the JDK (Java Development Kit) and the JRE (Java Runtime Environment)?

<p>JDK is a superset of the JRE and contains everything that is in the JRE, plus development tools</p> Signup and view all the answers

What is the purpose of the 'main' method in a Java program?

<p>It is the line at which the program will begin executing</p> Signup and view all the answers

What is the purpose of the 'new' operator in Java?

<p>It dynamically allocates memory for an object</p> Signup and view all the answers

Which keyword is used to declare a static method in Java?

<p>static</p> Signup and view all the answers

What is the purpose of the 'final' keyword in Java?

<p>To declare a variable that cannot be modified</p> Signup and view all the answers

What is the difference between call-by-value and call-by-reference in Java?

<p>Call-by-value passes the value of an argument, while call-by-reference passes the reference of an argument</p> Signup and view all the answers

What does the 'encapsulation' principle in object-oriented design refer to?

<p>Controlling access to instance variables using predefined functions</p> Signup and view all the answers

Which statement about constructors in Java is correct?

<p>Constructors are called in order of derivation, from superclass to subclass.</p> Signup and view all the answers

Which statement about the super( ) keyword in Java is correct?

<p>super( ) must be the first statement executed in a subclass' constructor.</p> Signup and view all the answers

Which statement about method overriding in Java is correct?

<p>A method in a subclass will always hide the version of the method defined by its superclass.</p> Signup and view all the answers

What is the purpose of dynamic method dispatch in Java?

<p>To determine which version of a method to execute based on the type of object referred at the time of call.</p> Signup and view all the answers

Which programming paradigm is the primary focus of Object Oriented Programming?

<p>Object Oriented Programming</p> Signup and view all the answers

What is the purpose of the 'new' operator in Java?

<p>To create a new instance of a class</p> Signup and view all the answers

What does the 'encapsulation' principle in object-oriented design refer to?

<p>The process of binding together the code and data it manipulates</p> Signup and view all the answers

Which principle of Object Oriented Programming allows code and data to be accessed via well-defined interfaces?

<p>Abstraction</p> Signup and view all the answers

Which one of the following is true about constructors in Java?

<p>Constructors have the same name as the class</p> Signup and view all the answers

Which one of the following is true about object initialization in Java?

<p>Object initialization is done immediately upon creation</p> Signup and view all the answers

Which one of the following is true about the 'new' operator in Java?

<p>The 'new' operator is used to create objects in Java</p> Signup and view all the answers

Which type of nested class in Java has access to other members of the enclosing class, even if they are declared private?

<p>Inner class</p> Signup and view all the answers

What is the purpose of the 'super' keyword in Java?

<p>To call the superclass' constructor</p> Signup and view all the answers

What is the order in which constructors for classes in a multilevel hierarchy are called?

<p>From top to bottom</p> Signup and view all the answers

Which statement about inheritance in Java is correct?

<p>A subclass includes all of the members of its superclass</p> Signup and view all the answers

Which of the following is true about overloading methods in Java?

<p>Overloaded methods can have different number of parameters but must have the same return type.</p> Signup and view all the answers

Which of the following is true about overloading constructors in Java?

<p>Overloaded constructors can have different number of parameters.</p> Signup and view all the answers

Which of the following is true about access control in Java?

<p>Protected members can only be accessed within their own package or by a subclass of their class in another package.</p> Signup and view all the answers

Which of the following is true about static variables in Java?

<p>Static variables are associated with the class, rather than with any object.</p> Signup and view all the answers

Which one of these is true about the JDK (Java Development Kit)?

<p>The JDK is a superset of the JRE and includes everything that is in the JRE, plus tools for developing programs and applications.</p> Signup and view all the answers

Which one of these is true about the JRE (Java Runtime Environment)?

<p>The JRE is only used by end users who want to run Java programs.</p> Signup and view all the answers

Which one of these is true about constructors in Java?

<p>Constructors are special methods that are automatically called when an object of a class is created.</p> Signup and view all the answers

Which one of these is true about object initialization in Java?

<p>Object initialization can be done by directly initializing instance variables or by defining and calling a special function.</p> Signup and view all the answers

Which keyword is used in Java to call the superclass' constructor?

<p>super</p> Signup and view all the answers

Which statement about method overriding in Java is correct?

<p>Method overriding occurs only when the names and the type signatures of the two methods are identical.</p> Signup and view all the answers

What is the purpose of dynamic method dispatch in Java?

<p>To determine the version of a method to execute based on the type of object referred at the time of the call.</p> Signup and view all the answers

Which statement about constructors in Java is correct?

<p>If super() is not used, the default or parameter-less constructor of each superclass will be executed.</p> Signup and view all the answers

Study Notes

Functional Programming

  • Focuses on functions and splitting bigger tasks into smaller ones

Object-Oriented Programming

  • Primary focus is on encapsulation, inheritance, and polymorphism
  • Allows code and data to be accessed via well-defined interfaces through the abstraction principle
  • Enables a single function to calculate the area for different shapes through polymorphism

Constructors in Java

  • If a class does not have a defined constructor, a default no-argument constructor is created by the compiler
  • Used to initialize objects when they are created
  • The 'super' keyword is used to call the superclass' constructor
  • Can be overloaded with different parameter lists
  • Are called in the order of the multilevel hierarchy

Object Initialization in Java

  • Occurs when an object is created
  • Can be initialized using constructors or instance initializers

Nested Classes in Java

  • A non-static nested class has access to other members of the enclosing class, even if they are declared private

Method Overloading and Overriding

  • Method overloading allows multiple methods with the same name but different parameter lists
  • Method overriding allows a subclass to provide a different implementation of a method already defined in its superclass

Access Control in Java

  • Uses public, private, protected, and default access modifiers to control access to classes and their members

Static Variables and Methods in Java

  • Static variables are shared by all instances of a class
  • Static methods can be called without creating an instance of a class

JDK and JRE

  • JDK (Java Development Kit) is a software development kit that includes a JRE, a compiler, and other tools
  • JRE (Java Runtime Environment) is a set of libraries and tools that provides a runtime environment for Java programs

'main' Method and 'new' Operator in Java

  • The 'main' method is the entry point for a Java program
  • The 'new' operator is used to create a new instance of a class

'final' Keyword in Java

  • Used to declare a constant variable, a method that cannot be overridden, or a class that cannot be inherited

Call-by-Value and Call-by-Reference in Java

  • Call-by-value passes a copy of an argument to a method
  • Call-by-reference passes a reference to an argument to a method

Encapsulation and Abstraction

  • Encapsulation is the principle of hiding implementation details and exposing only necessary information through well-defined interfaces
  • Abstraction is the principle of showing only essential features and hiding non-essential details

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

More Quizzes Like This

Use Quizgecko on...
Browser
Browser