CS 151 FINAL EXAM QUESTIONS AND
ANSWERS. VERIFIED 2025/2026.
The idea behind object-oriented programming is to structure a program around the real-world
concept of an object. Which of the following are the advantages of that approach?
A. It can make the program easier for humans to think about.
B. It usually makes the program run faster.
C. It can help with debugging. - ANS A, C
Which of the following statements is true?
A. An object can be used to produce multiple classes.
B. A class can be used to produce multiple objects - ANS B
Where are member variables declared?
A. Inside a class definition but outside the definition of any method in the class.
1 @COPYRIGHT 2025/2026 ALLRIGHTS RESERVED.
,B. Inside any method within a class.
C. Inside every method within a class. - ANS A
When is it OK to have an overloaded method (i.e., method with the same name as another
method) that has a different return type?
A. Always
B. Never
C. Only when the parameter list is also different - ANS C
Which of the following is true about a class's constructor?
A. A constructor is variable in a class that can be used to reference the objects
B. A constructor is a special method used to invoke other methods in the same class.
C. The constructor is a special method with the same name as the class and it's used to
instantiate objects from that class - ANS C
True or false: In software, objects come into existence ONLY when an application is running and
they do all of the work in the application. - ANS True
2 @COPYRIGHT 2025/2026 ALLRIGHTS RESERVED.
,True or false: An object is an instance of a class. Just like how a house or a building is an instance
of some blueprint that was designed by some architect. - ANS True
True or false: A class is a specification or blueprint or a design that contains details about how
an object will be in our application. - ANS True
What is the result of running the code?
(Hint: draw a memory model)
public class MyClass {
private int a;
public double b;
public MyClass(int first, double second)
{
this.a = first;
this.b = second;
}
public static void main(String[] args)
{
MyClass c1 = new MyClass(10, 20.5);
MyClass c2 = new MyClass(10, 31.5);
c2 = c1;
c1.a = 2;
System.out.println(c2.a);
}
} - ANS 2
3 @COPYRIGHT 2025/2026 ALLRIGHTS RESERVED.
, What is the output from running this code?
public class MyClass
{
private int a;
public double b;
public MyClass(int first, double second)
{
this.a = first;
this.b = second;
}
public static void incrementBoth(MyClass c1) {
c1.a = c1.a + 1;
c1.b = c1.b + 1.0;
}
public static void incrementA(int first)
{
first = first + 1;
}
public static void incrementB(double second)
{
second = second + 1.0;
}
public static void main(String[] args)
{
4 @COPYRIGHT 2025/2026 ALLRIGHTS RESERVED.
ANSWERS. VERIFIED 2025/2026.
The idea behind object-oriented programming is to structure a program around the real-world
concept of an object. Which of the following are the advantages of that approach?
A. It can make the program easier for humans to think about.
B. It usually makes the program run faster.
C. It can help with debugging. - ANS A, C
Which of the following statements is true?
A. An object can be used to produce multiple classes.
B. A class can be used to produce multiple objects - ANS B
Where are member variables declared?
A. Inside a class definition but outside the definition of any method in the class.
1 @COPYRIGHT 2025/2026 ALLRIGHTS RESERVED.
,B. Inside any method within a class.
C. Inside every method within a class. - ANS A
When is it OK to have an overloaded method (i.e., method with the same name as another
method) that has a different return type?
A. Always
B. Never
C. Only when the parameter list is also different - ANS C
Which of the following is true about a class's constructor?
A. A constructor is variable in a class that can be used to reference the objects
B. A constructor is a special method used to invoke other methods in the same class.
C. The constructor is a special method with the same name as the class and it's used to
instantiate objects from that class - ANS C
True or false: In software, objects come into existence ONLY when an application is running and
they do all of the work in the application. - ANS True
2 @COPYRIGHT 2025/2026 ALLRIGHTS RESERVED.
,True or false: An object is an instance of a class. Just like how a house or a building is an instance
of some blueprint that was designed by some architect. - ANS True
True or false: A class is a specification or blueprint or a design that contains details about how
an object will be in our application. - ANS True
What is the result of running the code?
(Hint: draw a memory model)
public class MyClass {
private int a;
public double b;
public MyClass(int first, double second)
{
this.a = first;
this.b = second;
}
public static void main(String[] args)
{
MyClass c1 = new MyClass(10, 20.5);
MyClass c2 = new MyClass(10, 31.5);
c2 = c1;
c1.a = 2;
System.out.println(c2.a);
}
} - ANS 2
3 @COPYRIGHT 2025/2026 ALLRIGHTS RESERVED.
, What is the output from running this code?
public class MyClass
{
private int a;
public double b;
public MyClass(int first, double second)
{
this.a = first;
this.b = second;
}
public static void incrementBoth(MyClass c1) {
c1.a = c1.a + 1;
c1.b = c1.b + 1.0;
}
public static void incrementA(int first)
{
first = first + 1;
}
public static void incrementB(double second)
{
second = second + 1.0;
}
public static void main(String[] args)
{
4 @COPYRIGHT 2025/2026 ALLRIGHTS RESERVED.