Save
Upgrade to remove ads
Busy. Please wait.
Log in with Clever
or

show password
Forgot Password?

Don't have an account?  Sign up 
Sign up using Clever
or

Username is available taken
show password


Make sure to remember your password. If you forget it there is no way for StudyStack to send you a reset link. You would need to create a new account.
Your email address is only used to allow you to reset your password. See our Privacy Policy and Terms of Service.


Already a StudyStack user? Log In

Reset Password
Enter the associated with your account, and we'll email you a link to reset your password.
focusNode
Didn't know it?
click below
 
Knew it?
click below
Don't Know
Remaining cards (0)
Know
0:00
Embed Code - If you would like this activity on your web page, copy the script below and paste it into your web page.

  Normal Size     Small Size show me how

OOP FORMATIVE 4

OOP FORMATIVE 4 TYPESHIII

QuestionAnswer
What is encapsulation in Java? A. Exposing all fields publicly B. Grouping unrelated data C. Hiding internal details and exposing only necessary parts D. Allowing multiple inheritance Answer: C – Encapsulation hides internal data using private fields and public getters/setters. Which concept allows a subclass to use fields and methods of its parent class? A. Polymorphism B. Inheritance C. Abstraction D. Composition
C – Encapsulation hides internal data using private fields and public getters/setters. Which concept allows a subclass to use fields and methods of its parent class? A. Polymorphism B. Inheritance C. Abstraction D. Composition Inheritance – enables code reuse and forms an “is-a” relationship.
B – Inheritance lets a subclass reuse and extend a superclass’s functionality. What is polymorphism in Java? A. Hiding data B. Code reuse C. Performing a single action in different forms D. Creating multiple classes The ability for one method or interface to perform different actions based on the object it is acting upon.
C – It allows a single method name to behave differently based on the object. What keyword is used to call a parent class constructor? A. parent B. this C. super D. extends super – used to call the parent class constructor or access its methods.
C – ‘super’ calls the superclass constructor or methods. What does the keyword this refer to? A. Parent class B. Current class C. Current object instance D. Static method C – Encapsulation hides internal data using private fields and public getters/setters.
C – ‘this’ refers to the current object calling the method. Which access modifier allows access only within the same package? A. private B. public C. default D. protected Default (no modifier) – package-private access.
C – The default (no modifier) grants access within the same package. Which keyword prevents a class from being inherited? A. static B. final C. abstract D. private final – prevents inheritance.
B – final classes cannot be extended. When a subclass defines a method with the same signature as its superclass, what is it called? A. Overloading B. Overriding C. Hiding D. Shadowing Method overriding – provides a new implementation in the subclass.
B – Overriding replaces the superclass method implementation. What can an abstract class contain? A. Only abstract methods B. Only static methods C. Both abstract and concrete methods D. Only constructors Both abstract and non-abstract methods – allows partial implementation.
C – Abstract classes can include both abstract and implemented methods. What keyword is used to implement an interface? A. inherit B. include C. implements D. extends implements – used to define the interface’s abstract methods in a class.
C – The ‘implements’ keyword lets a class use an interface. What is method overloading? A. Multiple methods with the same name but different parameters B. Same method in subclass C. Same method name and signature D. Multiple constructors only B – Inheritance lets a subclass reuse and extend a superclass’s functionality.
A – Overloading occurs when methods have the same name but different parameter lists. What is method overriding? A. Reusing private methods B. Creating multiple constructors C. Redefining a superclass method in subclass D. Calling parent constr Defining a method in a subclass with the same name and parameters as in the superclass.
C – Overriding changes a parent’s method behavior in a subclass. What is true about interface variables? A. They are instance variables B. They are public, static, and final by default C. They are protected D. They are private They are public, static, and final by default.
B – Interface variables are constants shared across all implementations. Can something be both abstract and final? A. Yes B. No C. Only in interfaces D. Only in constructors No – abstract means “must be overridden” and final means “cannot be overridden.”
B – abstract requires overriding, while final prevents it. What happens if you try to instantiate an abstract class? A. Runtime error B. Compilation error C. Logical error D. Works normally Compilation error – abstract classes cannot be instantiated directly.
B – Abstract classes cannot be directly instantiated. Can an interface extend another interface? A. No B. Yes C. Only one D. Only if abstract Yes – interfaces can extend other interfaces.
B – Interfaces can extend other interfaces. Can a class implement multiple interfaces? A. No B. Yes C. Only if abstract D. Only if final C – It allows a single method name to behave differently based on the object.
B – A class can implement multiple interfaces, allowing multiple inheritance of type. What is the default access modifier for interface methods? A. protected B. public and abstract C. package-private D. private public and abstract.
B – All interface methods are public and abstract by default. Can constructors be defined in interfaces? A. Yes B. No C. Only if static D. Only if default No – interfaces cannot have constructors.
B – Interfaces cannot have constructors. What is the main purpose of abstraction? A. To group similar data B. To show essential features while hiding implementation details C. To increase code size D. To avoid inheritance To show essential features while hiding implementation details.
B – Abstraction hides complexity and exposes only what’s necessary. What is the purpose of the super keyword? A. To call static methods B. To access child class members C. To access parent class members or constructor D. To define private varia To access members or constructors of the parent class.
C – super refers to the immediate parent class. Can a static method be overridden? A. Yes B. No C. Only if protected D. Only in interfaces No – static methods belong to the class, not instances.
B – Static methods belong to the class, not to instances, so they can’t be overridden. What is the difference between overloading and overriding? A. Both are the same B. Overloading happens at runtime; overriding at compile-time C. Overloading is C – ‘super’ calls the superclass constructor or methods.
C – Overloading = compile-time, overriding = runtime polymorphism. What is a constructor in Java? A. A special method used to initialize objects B. A static method C. A final variable D. An overridden method A special method used to initialize objects.
A – Constructors initialize object states during creation. Can constructors be inherited? A. Yes B. No C. Only if public D. Only if protected No – they are not inherited by subclasses.
B – Constructors are not inherited, but can be called using super(). Having multiple constructors with different parameter lists.
B. Current class The compiler provides a default no-argument constructor.
C. Current object instance A constructor that creates a new object by copying another object’s values.
D. Static method Answer C – ‘this’ refers to the current object calling the method.
A method that belongs to the class, not any specific instance.
Which access modifier allows access only within the same package? No – they can only access static members directly.
A. private Yes – since both belong to the class level.
B. public Code reuse and logical hierarchy between classes.
C. default Allows a class to inherit from another class.
D. protected Answer C – The default (no modifier) grants access within the same package.
java.lang.Object
Which keyword prevents a class from being inherited? None – constructors do not have a return type.
A. static Yes – often used in singleton patterns.
B. final A constant whose value cannot be changed once assigned.
C. abstract A method that cannot be overridden by subclasses.
D. private Answer B – final classes cannot be extended.
A method without a body, meant to be implemented by subclasses.
When a subclass defines a method with the same signature as its superclass, what is it called? An abstract class can have concrete methods and state; interfaces only define behavior contracts.
A. Overloading When a class inherits features from more than one parent type; supported in Java via interfaces.
B. Overriding Treating a subclass object as an instance of its superclass.
C. Hiding Casting a superclass reference back to a subclass type.
D. Shadowing Answer B – Overriding replaces the superclass method implementation.
To test whether an object is an instance of a specific class or subclass.
What can an abstract class contain? Yes – they can be used to initialize common fields.
A. Only abstract methods The subclass must be declared abstract.
B. Only static methods Method overriding and dynamic method dispatch.
C. Both abstract and concrete methods The process where the method call is resolved at runtime based on the object type.
D. Only constructors Answer C – Abstract classes can include both abstract and implemented methods.
Method overriding.
What keyword is used to implement an interface? Yes – but they cannot be abstract.
A. inherit Yes – using the default keyword since Java 8.
B. include To provide a default implementation that implementing classes may override.
C. implements Yes – since Java 8.
D. extends Answer C – The ‘implements’ keyword lets a class use an interface.
An event that disrupts the normal flow of program execution.
What is method overloading? The process of managing runtime errors using try-catch blocks.
A. Multiple methods with the same name but different parameters throw – used to explicitly raise an exception.
B. Same method in subclass throws – indicates that a method might throw an exception.
C. Same method name and signature java.lang.Throwable
D. Multiple constructors only Answer A – Overloading occurs when methods have the same name but different parameter lists.
Exceptions that must be handled or declared (e.g., IOException).
What is method overriding? Runtime exceptions that do not require explicit handling (e.g., NullPointerException).
A. Reusing private methods throw is used to raise an exception; throws is used to declare it.
B. Creating multiple constructors The program terminates abnormally.
C. Redefining a superclass method in subclass Executes code regardless of whether an exception occurs or not.
D. Calling parent constructor Answer C – Overriding changes a parent’s method behavior in a subclass.
Yes – to handle different exception types separately.
What is true about interface variables? Yes – using `catch (Exception1 | Exception2 e)`.
A. They are instance variables A user-defined class extending Exception or RuntimeException.
B. They are public, static, and final by default A custom exception that extends Exception.
C. They are protected A custom exception that extends RuntimeException.
D. They are private Answer B – Interface variables are constants shared across all implementations.
To test assumptions in code during development.
Can something be both abstract and final? Using the -ea flag when running a program.
A. Yes An AssertionError is thrown.
B. No assert
C. Only in interfaces == compares references; equals() compares object content.
D. Only in constructors Answer B – abstract requires overriding, while final prevents it.
A namespace that organizes related classes and interfaces.
What happens if you try to instantiate an abstract class? To access classes from other packages.
A. Runtime error The unnamed package where classes without a package declaration reside.
B. Compilation error public – accessible everywhere; protected – within package and by subclasses.
C. Logical error Allows access to static members without qualifying the class name.
D. Works normally Answer B – Abstract classes cannot be directly instantiated.
A class defined within another class.
Can an interface extend another interface? An inner class declared static, not tied to an instance of the outer class.
A. No Yes – including private ones.
B. Yes A class declared within a method.
C. Only one A class without a name, often used for short implementations.
D. Only if abstract Answer B – Interfaces can extend other interfaces.
An interface with exactly one abstract method.
Can a class implement multiple interfaces? @FunctionalInterface
A. No Prevents a field from being serialized.
B. Yes Ensures visibility of changes across threads.
C. Only if abstract Used to control thread access to critical code blocks.
D. Only if final Answer B – A class can implement multiple interfaces, allowing multiple inheritance of type.
No – static methods are class-bound, not instance-bound.
What is the default access modifier for interface methods? final prevents reassignment; immutable means the object’s state cannot change.
A. protected Throws ArithmeticException.
B. public and abstract Results in Infinity or NaN.
C. package-private Terminates the JVM immediately.
D. private Answer B – All interface methods are public and abstract by default.
No – you can only request it with System.gc(), but it’s not guaranteed.
Can constructors be defined in interfaces? Called by the garbage collector before object destruction (deprecated in modern Java).
A. Yes Prevents serialization of certain fields.
B. No The process of converting an object into a byte stream for storage or transfer.
C. Only if static The process of reconstructing an object from a byte stream.
D. Only if default Answer B – Interfaces cannot have constructors.
What is the main purpose of abstraction?
A. To group similar data
B. To show essential features while hiding implementation details
C. To increase code size
D. To avoid inheritance Answer B – Abstraction hides complexity and exposes only what’s necessary.
What is the purpose of the super keyword?
A. To call static methods
B. To access child class members
C. To access parent class members or constructor
D. To define private variables Answer C – super refers to the immediate parent class.
Can a static method be overridden?
A. Yes
B. No
C. Only if protected
D. Only in interfaces Answer B – Static methods belong to the class, not to instances, so they can’t be overridden.
What is the difference between overloading and overriding?
A. Both are the same
B. Overloading happens at runtime; overriding at compile-time
C. Overloading is compile-time; overriding is runtime
D. Neither happens automatically Answer C – Overloading = compile-time, overriding = runtime polymorphism.
What is a constructor in Java?
A. A special method used to initialize objects
B. A static method
C. A final variable
D. An overridden method Answer A – Constructors initialize object states during creation.
Can constructors be inherited?
A. Yes
B. No
C. Only if public
D. Only if protected Answer B – Constructors are not inherited, but can be called using super().
Created by: stigma
 

 



Voices

Use these flashcards to help memorize information. Look at the large card and try to recall what is on the other side. Then click the card to flip it. If you knew the answer, click the green Know box. Otherwise, click the red Don't know box.

When you've placed seven or more cards in the Don't know box, click "retry" to try those cards again.

If you've accidentally put the card in the wrong box, just click on the card to take it out of the box.

You can also use your keyboard to move the cards as follows:

If you are logged in to your account, this website will remember which cards you know and don't know so that they are in the same box the next time you log in.

When you need a break, try one of the other activities listed below the flashcards like Matching, Snowman, or Hungry Bug. Although it may feel like you're playing a game, your brain is still making more connections with the information to help you out.

To see how well you know the information, try the Quiz or Test activity.

Pass complete!
"Know" box contains:
Time elapsed:
Retries:
restart all cards