0% found this document useful (0 votes)
5 views2 pages

OBJPROG REVquiz

The document contains a series of questions and answers related to Java programming concepts, including object instantiation, method overloading, inheritance, and array manipulation. Key topics covered include the use of keywords like 'this', 'super', and 'extends', as well as concepts such as encapsulation, polymorphism, and recursion. The document serves as a study guide for understanding fundamental Java programming principles.

Uploaded by

harlynmaebatalan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

OBJPROG REVquiz

The document contains a series of questions and answers related to Java programming concepts, including object instantiation, method overloading, inheritance, and array manipulation. Key topics covered include the use of keywords like 'this', 'super', and 'extends', as well as concepts such as encapsulation, polymorphism, and recursion. The document serves as a study guide for understanding fundamental Java programming principles.

Uploaded by

harlynmaebatalan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1. What does the keyword this refer to in a Java 18.

Which keyword is used within a subclass to


class? refer to its immediate superclass? super
The current object instance 19. What is method overriding?
2. Which of the following correctly instantiates an Defining a method with the same signature in
object of the class Student using a parameterized a subclass to replace the superclass version
constructor? 20. If a subclass does not override a method
Student s = new Student("John", 20); inherited from its superclass, what happens
3. What is method overloading in a Java class? when that method is invoked on an object of the
Defining multiple methods in the same class subclass?
with the same name but different parameter lists The superclass version of the method is executed
4. Which of the following is true regarding 21. Which keyword is used to indicate that one class
instance variables? is derived from another? extends
Each object has its own copy of instance 22. Which of the following is an example of runtime
variables. polymorphism in Java? Method overriding
5. Which access modifier allows a class member to 23. Which scenario best illustrates polymorphism in
be accessed only within its own class? private Java?
6. Which statement about a default (no-argument) A variable of type Animal referring to an object
constructor is true? of type Dog
It is automatically provided by the compiler if 24. How do you call a superclass constructor from a
no constructors are declared. subclass? super()
7. Which keyword is used to create a new object in 25. When a subclass overrides a method, which
Java? new method is executed when the method is called
8. How can you call one constructor from another on a superclass reference that points to a
in the same class? subclass object? The subclass version
Using the keyword this 26. What is the effect of declaring a method as final
9. In Java, what is the scope of a variable declared in a superclass?
within a method? The method cannot be overridden by subclasses
Local to the method 27. What is the main advantage of polymorphism in
10. How is encapsulation best achieved in Java? Java?
Using private variables with public getter and It enables one interface to be used for a general
setter methods class of actions
11. What is the default value of an uninitialized 28. What is dynamic method dispatch in Java?
instance variable of type int in a class? 0 Determining which overridden method to call
12. Which of the following best describes a Java at runtime
class? 29. What does it mean when a method is
A blueprint for creating objects “overridden”?
13. What is the primary purpose of a constructor in a It has the same signature in both superclass and
class? subclass, with the subclass providing its own
To initialize new objects implementation
14. Which of the following statements about objects 30. Which of the following methods cannot be
in Java is false? overridden in a subclass? Private methods
Objects are automatically destroyed when
they go out of scope. 1. Which loop guarantees that its body is executed
15. What does it mean when a variable is declared at least once? do-while loop
as static in a class? 2. Which of the following is true about the
It belongs to the class rather than any enhanced for-loop in Java?
instance. It iterates over elements without using an index
16. In Java, if a superclass reference variable holds variable.
an object of a subclass, which version of an 3. Which loop would be most appropriate for
overridden method is executed when called on reading input until a sentinel value is entered?
that reference? while-loop
The subclass’s version 4. In a while-loop, what must eventually happen to
17. Which statement is true about static methods in avoid an infinite loop?
the context of inheritance?: The condition must be false at some point
They are hidden, not overridden. 5. Which of the following correctly exits a loop
immediately? Break
6. What is the primary difference between a for-
loop and an enhanced for-loop?
The for-loop requires an index variable while
the enhanced for-loop does not.
7. What is the return type of a method that does not
return any value? void
8. Which of the following is a correct method
signature for a method that accepts two integers
and returns their sum? public int add(int a, int b)
9. Which of the following is an example of a
proper method call for a non-static method
named display in the same class?
Both A and C (i.e., this.display(); and display();)
10. Which statement about recursion in Java
methods is true?
A recursive method must have a base case to
prevent infinite recursion.
11. What is method overloading?
Having methods with the same name and
different parameter lists in the same class
12. What is the main advantage of using methods in
Java programming?
They allow for code reusability and better
organization.
13. Which keyword is used to define a method that
does not return a value? void
14. In Java, what is the scope of a method’s
parameters? Local to the method
15. What does the static keyword indicate when
used in a method declaration? The method
belongs to the class, not to any instance.
16. How does a Vector differ from an array in Java?
A Vector is dynamic and can grow, while an
array has a fixed size.
17. Which property returns the number of elements
in a Java array? length
18. Which of the following is true regarding
accessing elements in a Java array?
Array indices start at 0.
19. How do you declare a one-dimensional array of
integers with 5 elements in Java?
int[] array = new int[5];
20. What is the default initial capacity of a Java
Vector? 10
21. How do you declare a two-dimensional array of
integers in Java?
Both A and B (int[][] matrix; and int matrix[]
[];)
22. Which method is used to add an element to a
Vector in Java? add()
23. Which method would you use to remove an
element from a Vector at a specific index?
remove()
24. How do you access the third element in an array
named data? data[2]

You might also like