0% found this document useful (0 votes)
5 views

OBJPROG_REV

The document contains a series of questions and answers related to Java programming concepts, including object instantiation, method overriding, encapsulation, polymorphism, and array handling. It covers various topics such as constructors, access modifiers, static methods, and the differences between arrays and Vectors. Each question is followed by a concise answer, providing a comprehensive overview of fundamental Java 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 PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

OBJPROG_REV

The document contains a series of questions and answers related to Java programming concepts, including object instantiation, method overriding, encapsulation, polymorphism, and array handling. It covers various topics such as constructors, access modifiers, static methods, and the differences between arrays and Vectors. Each question is followed by a concise answer, providing a comprehensive overview of fundamental Java 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 PDF, TXT or read online on Scribd
You are on page 1/ 2

1. What does the keyword this refer to in a Java 19. What is method overriding?

class? Defining a method with the same signature in a


The current object instance subclass to replace the superclass version
2. Which of the following correctly instantiates an 20. If a subclass does not override a method
object of the class Student using a parameterized inherited from its superclass, what happens
constructor? when that method is invoked on an object of the
Student s = new Student("John", 20); subclass?
3. What is method overloading in a Java class? The superclass version of the method is executed
Defining multiple methods in the same class 21. Which keyword is used to indicate that one class
with the same name but different parameter lists is derived from another? extends
4. Which of the following is true regarding 22. Which of the following is an example of runtime
instance variables? polymorphism in Java? Method overriding
Each object has its own copy of instance 23. Which scenario best illustrates polymorphism in
variables. Java?
5. Which access modifier allows a class member to A variable of type Animal referring to an object
be accessed only within its own class? private of type Dog
6. Which statement about a default (no-argument) 24. How do you call a superclass constructor from a
constructor is true? subclass? super()
It is automatically provided by the compiler if 25. When a subclass overrides a method, which
no constructors are declared. method is executed when the method is called on
7. Which keyword is used to create a new object in a superclass reference that points to a subclass
Java? new object? The subclass version
8. How can you call one constructor from another 26. What is the effect of declaring a method as final
in the same class? in a superclass?
Using the keyword this The method cannot be overridden by subclasses
9. In Java, what is the scope of a variable declared 27. What is the main advantage of polymorphism in
within a method? Java?
Local to the method It enables one interface to be used for a general
10. How is encapsulation best achieved in Java? class of actions
Using private variables with public getter and 28. What is dynamic method dispatch in Java?
setter methods Determining which overridden method to call at
11. What is the default value of an uninitialized runtime
instance variable of type int in a class? 0 29. What does it mean when a method is
12. Which of the following best describes a Java “overridden”?
class? It has the same signature in both superclass and
A blueprint for creating objects subclass, with the subclass providing its own
13. What is the primary purpose of a constructor in a implementation
class? 30. Which of the following methods cannot be
To initialize new objects overridden in a subclass? Private methods
14. Which of the following statements about objects
in Java is false? 1. Which loop guarantees that its body is executed
Objects are automatically destroyed when they at least once? do-while loop
go out of scope. 2. Which of the following is true about the
15. What does it mean when a variable is declared enhanced for-loop in Java?
as static in a class? It iterates over elements without using an index
It belongs to the class rather than any instance. variable.
16. In Java, if a superclass reference variable holds 3. Which loop would be most appropriate for
an object of a subclass, which version of an reading input until a sentinel value is entered?
overridden method is executed when called on while-loop
that reference? 4. In a while-loop, what must eventually happen to
The subclass’s version avoid an infinite loop?
17. Which statement is true about static methods in The condition must be false at some point
the context of inheritance?: 5. Which of the following correctly exits a loop
They are hidden, not overridden. immediately? Break
18. Which keyword is used within a subclass to refer 6. What is the primary difference between a for-
to its immediate superclass? super 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