zuai-logo
zuai-logo
  1. AP Computer Science A
FlashcardFlashcard
Study GuideStudy GuideQuestion BankQuestion BankGlossaryGlossary

What is the definition of Object-Oriented Programming (OOP)?

A programming paradigm based on the concept of 'objects', which contain data in the form of fields (attributes) and code in the form of procedures (methods).

Flip to see [answer/question]
Flip to see [answer/question]
Revise later
SpaceTo flip
If confident

All Flashcards

What is the definition of Object-Oriented Programming (OOP)?

A programming paradigm based on the concept of 'objects', which contain data in the form of fields (attributes) and code in the form of procedures (methods).

What is the definition of a Class?

A blueprint or template for creating objects. It defines the characteristics and behaviors that objects of that class will have.

What is the definition of an Object?

A specific instance of a class. It's a concrete entity created from a class blueprint.

What is the definition of a Constructor?

A special method used to create and initialize objects of a class.

What is the definition of a Method?

A function associated with an object, defining its behavior.

What is the definition of a Reference Type?

A data type that stores the memory address of an object, rather than the object's actual value.

What is the definition of Abstraction?

Showing only essential attributes and hiding unnecessary information.

What is the definition of Encapsulation?

Bundling of data and methods that operate on that data within a class, and restricting direct access to some of the object's components.

What is the definition of Inheritance?

A mechanism where a new class inherits properties and behaviors from an existing class.

What is the definition of Polymorphism?

The ability of an object to take on many forms.

What are the differences between primitive types and reference types?

Primitive types store values directly; reference types store memory addresses. Primitive types start with lowercase; reference types start with uppercase.

What is the difference between == and .equals() when comparing objects?

== compares memory addresses (references); .equals() compares the content of the objects (if properly implemented).

Compare the use of the String class with the Math class.

String is used to create and manipulate text; Math provides static methods for mathematical operations. String objects are created with new or string literals; Math cannot be instantiated.

What is the difference between a static method and an instance method?

A static method belongs to the class itself and is called using the class name; an instance method belongs to an object of the class and is called using the object's name.

Compare Abstraction and Encapsulation.

Abstraction focuses on hiding complexity and showing only essential features, while encapsulation focuses on bundling data and methods that operate on that data, protecting it from outside access.

Compare Inheritance and Polymorphism.

Inheritance allows a class to inherit properties and behaviors from another class, promoting code reuse, while polymorphism allows objects of different classes to be treated as objects of a common type, enabling flexibility and extensibility.

What does the following code output?

java
String str = "Hello";
String str2 = str;
str2 = "World";
System.out.println(str);

Hello

Identify the error in the following code:

java
public class Example {
  int x;
  public static void main(String[] args) {
    Example obj = new Example;
    System.out.println(obj.x);
  }
}

Missing parentheses in the constructor call: new Example().

What does the following code output?

java
public class Test {
    int num;
    public Test(int num) {
        this.num = num;
    }
    public static void main(String[] args) {
        Test t1 = new Test(10);
        Test t2 = t1;
        t2.num = 20;
        System.out.println(t1.num);
    }
}

20

What does the following code output?

java
String str1 = new String("example");
String str2 = new String("example");
System.out.println(str1 == str2);

false

Identify the error in the following code:

java
public class MyClass {
    private int x;

    public void MyClass(int x) { // Intended to be a constructor
        this.x = x;
    }

    public static void main(String[] args) {
        MyClass obj = new MyClass(5);
        System.out.println(obj.x);
    }
}

The 'constructor' MyClass(int x) is actually a method because it has a return type (void is implied). This means the value of x is never properly initialized, and x will default to 0, leading to a compilation error as the constructor is never called.

What does the following code output?

java
public class Example {
    public static void main(String[] args) {
        String s1 = "Hello";
        String s2 = "Hello";
        System.out.println(s1 == s2);
    }
}

true

What will be the output of this code?

java
public class Example {
    public static void main(String[] args) {
        String str = "Coding";
        System.out.println(str.substring(2, 4));
    }
}

di

What does the following code output?

java
public class Test {
    int x = 5;

    public static void main(String[] args) {
        Test t1 = new Test();
        Test t2 = new Test();
        t1.x = 10;
        System.out.println(t2.x);
    }
}

5

What does the following code output?

java
public class Example {
    public static void main(String[] args) {
        String s = "Hello World";
        System.out.println(s.indexOf("World"));
    }
}

6

What is wrong with the following code?

java
public class Example {
    public static void main(String[] args) {
        Math m = new Math();
        System.out.println(m.sqrt(25));
    }
}

You cannot instantiate the Math class. All methods in the Math class are static, so you should call them using Math.sqrt(25).