Abstraction and Program Design - AP Computer Science A
Card 1 of 30
What is the result of 'System.out.println(7.0/2);'?
What is the result of 'System.out.println(7.0/2);'?
Tap to reveal answer
The result is 3.5, due to floating-point division. Double operand promotes calculation to floating-point arithmetic.
The result is 3.5, due to floating-point division. Double operand promotes calculation to floating-point arithmetic.
← Didn't Know|Knew It →
What is the result of 'System.out.println(7/2);'?
What is the result of 'System.out.println(7/2);'?
Tap to reveal answer
The result is 3, due to integer division. Both operands are integers, so result truncates decimal portion.
The result is 3, due to integer division. Both operands are integers, so result truncates decimal portion.
← Didn't Know|Knew It →
Identify the error: 'class B extends A, C {}'
Identify the error: 'class B extends A, C {}'
Tap to reveal answer
Java does not support multiple inheritance of classes. Classes can only extend one superclass in Java.
Java does not support multiple inheritance of classes. Classes can only extend one superclass in Java.
← Didn't Know|Knew It →
What is the signature of a main method in Java?
What is the signature of a main method in Java?
Tap to reveal answer
public static void main(String[] args). Entry point for Java applications, must match exact format.
public static void main(String[] args). Entry point for Java applications, must match exact format.
← Didn't Know|Knew It →
Identify the error: 'interface I { void method(){} }'
Identify the error: 'interface I { void method(){} }'
Tap to reveal answer
Interfaces cannot have method bodies. Only default and static methods can have implementations.
Interfaces cannot have method bodies. Only default and static methods can have implementations.
← Didn't Know|Knew It →
Correct this snippet: 'int x = new int();'.
Correct this snippet: 'int x = new int();'.
Tap to reveal answer
Use 'int x;' or 'Integer x = new Integer();'. Primitives cannot use constructor syntax, only reference types.
Use 'int x;' or 'Integer x = new Integer();'. Primitives cannot use constructor syntax, only reference types.
← Didn't Know|Knew It →
Identify the error: 'class A { static int x; }'
Identify the error: 'class A { static int x; }'
Tap to reveal answer
No error; the syntax is correct. Static variables are properly declared at class level.
No error; the syntax is correct. Static variables are properly declared at class level.
← Didn't Know|Knew It →
Identify the error: 'public void myMethod(int a, int a)'.
Identify the error: 'public void myMethod(int a, int a)'.
Tap to reveal answer
Duplicate parameter name 'a'. Parameter names must be unique within method signature.
Duplicate parameter name 'a'. Parameter names must be unique within method signature.
← Didn't Know|Knew It →
Identify an example of polymorphism in Java.
Identify an example of polymorphism in Java.
Tap to reveal answer
Method overriding is an example of polymorphism. Subclass methods can replace superclass method behavior.
Method overriding is an example of polymorphism. Subclass methods can replace superclass method behavior.
← Didn't Know|Knew It →
Identify the keyword to declare a class as abstract.
Identify the keyword to declare a class as abstract.
Tap to reveal answer
The 'abstract' keyword is used to declare an abstract class. Marks class as incomplete, requiring subclass implementation.
The 'abstract' keyword is used to declare an abstract class. Marks class as incomplete, requiring subclass implementation.
← Didn't Know|Knew It →
What is the default access modifier in Java?
What is the default access modifier in Java?
Tap to reveal answer
The default access modifier is package-private. Accessible within package but not from outside packages.
The default access modifier is package-private. Accessible within package but not from outside packages.
← Didn't Know|Knew It →
What is the main advantage of using inheritance?
What is the main advantage of using inheritance?
Tap to reveal answer
Inheritance promotes code reuse. Avoids duplicating code across multiple related classes.
Inheritance promotes code reuse. Avoids duplicating code across multiple related classes.
← Didn't Know|Knew It →
Which keyword is used to implement an interface in Java?
Which keyword is used to implement an interface in Java?
Tap to reveal answer
The 'implements' keyword is used to implement an interface. Creates contractual obligation to provide method implementations.
The 'implements' keyword is used to implement an interface. Creates contractual obligation to provide method implementations.
← Didn't Know|Knew It →
Which keyword is used to inherit a class in Java?
Which keyword is used to inherit a class in Java?
Tap to reveal answer
The 'extends' keyword is used to inherit a class. Establishes is-a relationship between parent and child classes.
The 'extends' keyword is used to inherit a class. Establishes is-a relationship between parent and child classes.
← Didn't Know|Knew It →
How does encapsulation improve code robustness?
How does encapsulation improve code robustness?
Tap to reveal answer
Encapsulation protects an object's internal state from unintended modification. Private fields prevent direct external manipulation of data.
Encapsulation protects an object's internal state from unintended modification. Private fields prevent direct external manipulation of data.
← Didn't Know|Knew It →
Identify a method to achieve abstraction in Java.
Identify a method to achieve abstraction in Java.
Tap to reveal answer
Abstraction can be achieved using abstract classes and interfaces. Both provide contracts without revealing implementation details.
Abstraction can be achieved using abstract classes and interfaces. Both provide contracts without revealing implementation details.
← Didn't Know|Knew It →
What is the significance of the 'protected' keyword?
What is the significance of the 'protected' keyword?
Tap to reveal answer
'protected' allows access within the same package and subclasses. Package access plus inheritance-based access for subclasses.
'protected' allows access within the same package and subclasses. Package access plus inheritance-based access for subclasses.
← Didn't Know|Knew It →
What is the significance of the 'private' keyword?
What is the significance of the 'private' keyword?
Tap to reveal answer
'private' restricts access to the class itself. Most restrictive access, only within declaring class.
'private' restricts access to the class itself. Most restrictive access, only within declaring class.
← Didn't Know|Knew It →
What is the significance of the 'public' keyword?
What is the significance of the 'public' keyword?
Tap to reveal answer
'public' makes a class, method, or field accessible from any other class. Broadest access level, no restrictions on usage.
'public' makes a class, method, or field accessible from any other class. Broadest access level, no restrictions on usage.
← Didn't Know|Knew It →
What is the purpose of the 'final' keyword in Java?
What is the purpose of the 'final' keyword in Java?
Tap to reveal answer
'final' is used to declare constants, prevent inheritance, and prevent method overriding. Prevents modification, inheritance, or method overriding.
'final' is used to declare constants, prevent inheritance, and prevent method overriding. Prevents modification, inheritance, or method overriding.
← Didn't Know|Knew It →
What is the purpose of the 'this' keyword in Java?
What is the purpose of the 'this' keyword in Java?
Tap to reveal answer
'this' is used to refer to the current object instance. Distinguishes between instance variables and parameters with same names.
'this' is used to refer to the current object instance. Distinguishes between instance variables and parameters with same names.
← Didn't Know|Knew It →
What is a static method in Java?
What is a static method in Java?
Tap to reveal answer
A static method belongs to the class rather than any object instance. Called on class itself, not requiring object instantiation.
A static method belongs to the class rather than any object instance. Called on class itself, not requiring object instantiation.
← Didn't Know|Knew It →
What is a concrete class?
What is a concrete class?
Tap to reveal answer
A concrete class is a class that has no abstract methods. Can be instantiated directly, no abstract methods present.
A concrete class is a class that has no abstract methods. Can be instantiated directly, no abstract methods present.
← Didn't Know|Knew It →
Identify a benefit of using abstraction.
Identify a benefit of using abstraction.
Tap to reveal answer
Abstraction reduces complexity and increases efficiency. Simplifies development by hiding unnecessary implementation details.
Abstraction reduces complexity and increases efficiency. Simplifies development by hiding unnecessary implementation details.
← Didn't Know|Knew It →
What is a constructor in Java?
What is a constructor in Java?
Tap to reveal answer
A constructor is a special method to initialize objects. Called automatically when creating new object instances.
A constructor is a special method to initialize objects. Called automatically when creating new object instances.
← Didn't Know|Knew It →
What is polymorphism in OOP?
What is polymorphism in OOP?
Tap to reveal answer
Polymorphism allows for methods to do different things based on the object it is acting upon. Enables same method name to behave differently across classes.
Polymorphism allows for methods to do different things based on the object it is acting upon. Enables same method name to behave differently across classes.
← Didn't Know|Knew It →
What is a subclass in Java?
What is a subclass in Java?
Tap to reveal answer
A subclass is a class that inherits from another class, the superclass. Also called child class, extends functionality of parent class.
A subclass is a class that inherits from another class, the superclass. Also called child class, extends functionality of parent class.
← Didn't Know|Knew It →
What is a superclass in Java?
What is a superclass in Java?
Tap to reveal answer
A superclass is the class from which a subclass inherits. Also called parent class, provides structure for child classes.
A superclass is the class from which a subclass inherits. Also called parent class, provides structure for child classes.
← Didn't Know|Knew It →
What does 'inheritance' mean in OOP?
What does 'inheritance' mean in OOP?
Tap to reveal answer
Inheritance allows a class to inherit fields and methods from another class. Enables code reuse by establishing parent-child class relationships.
Inheritance allows a class to inherit fields and methods from another class. Enables code reuse by establishing parent-child class relationships.
← Didn't Know|Knew It →
Define encapsulation in object-oriented programming.
Define encapsulation in object-oriented programming.
Tap to reveal answer
Encapsulation is bundling data with methods that operate on it. Key principle protecting data integrity through controlled access.
Encapsulation is bundling data with methods that operate on it. Key principle protecting data integrity through controlled access.
← Didn't Know|Knew It →