Docsity

CSC 142 Final Exam: Java Programming (Intermediate), Exams of Java Programming

Toggle sidebar
bg1
Page 1 of 28
CSC 142 FINAL EXAM QUESTIONS WITH
VERIFIED SOLUTIONS NEW MODIFIED
TESTED AND APPROVED
What do we call the attributes associated with the object, When an object is
created?
instance variables
fixed attributes
instance methods
class instances --CORRECT ANSWER--instance variables
In UML diagrams, to indicate that an instance variable or method is public, we
used which symbol?
#
-
+
* --CORRECT ANSWER--+
Which of the following is true when you examine the following declarations:
int tag;
DO NOT COPY
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download CSC 142 Final Exam: Java Programming (Intermediate) and more Exams Java Programming in PDF only on Docsity!

CSC 142 FINAL EXAM QUESTIONS WITH

VERIFIED SOLUTIONS NEW MODIFIED

TESTED AND APPROVED

What do we call the attributes associated with the object, When an object is created? instance variables fixed attributes instance methods class instances --CORRECT ANSWER--instance variables In UML diagrams, to indicate that an instance variable or method is public, we used which symbol?

  • --CORRECT ANSWER--+ Which of the following is true when you examine the following declarations: int tag;

DO NOT COPY

String title; tag is a reference variable, and title is a primitive. both are reference variables tag is a reference variable, and title is a primitive. tag is a primitive variable, and title is a reference variable. --CORRECT ANSWER--tag is a primitive variable, and title is a reference variable. All classes in Java can automatically invoke the toString() method. True False --CORRECT ANSWER--True The signature of a method consists of ____________. method name and parameter list method name parameter list method name, parameter list and return type --CORRECT ANSWER--method name and parameter list

DO NOT COPY

false, 0, null --CORRECT ANSWER--false, 0, null All real-world objects have in common certain attributes, what are they? Objects have identity (unique names), state (data), and behavior (action). Objects have state (data) and behavior (action). Objects have memory location, size and weight. All of the above --CORRECT ANSWER--Objects have identity (unique names), state (data), and behavior (action). How about Software objects, what attributes do they have in common? Software objects have CPU, RAM, and processors. Software objects have identity (unique identifiers) , state (data), and behavior (action). Software objects have instance variables and storage space. All looks good to me. --CORRECT ANSWER--Software objects have identity (unique identifiers) , state (data), and behavior (action). We keep mentioning the concept of scope., which of the following describes at best what the scope of a local variable? the entire java file.

DO NOT COPY

inside the class, and inside every method. inside the parentheses of a method signature. the method in which the local variable is defined. --CORRECT ANSWER--the method in which the local variable is defined. It is highly recommended and for privacy and security, that in object-oriented programming to make all of a class's instance variables public methods public instance variables and methods public instance variables private --CORRECT ANSWER--instance variables private Let's take a look bac again to our House Catalogues analogy example. We can think of a class as a design/blueprint that describes a given house and ________ are instantiated of that house built from the blueprint. attributes methods fields objects --CORRECT ANSWER--objects A SETTER method is a method that accepts a value from a class's instance variable and does not change.

DO NOT COPY

completely create a new class create a new Java file --CORRECT ANSWER--create an object that represents a given class The private access specifier for class member (instance variable, method) specifies that the field may can't be accessed by written code outside the class. True False --CORRECT ANSWER--True In Java, a method may have two parameters or more must have at least one parameter variables. never accepts parameter variables. may have none or many parameter variables. --CORRECT ANSWER--may have none or many parameter variables. et's do some UML study, If you read the following method, what does it mean?

  • setTicektNumber(price:double) : void a public method that accepts a double data type and does not return a value

DO NOT COPY

a public field called TicketNumber that is designed as a double data type a private field called TicketNumber that is designed as a double data type a private method that accepts a double data type and does not return a value -- CORRECT ANSWER--a public method that accepts a double data type and does not return a value A GET method is the one that saves a passed value in a class's field or somehow changed the value of an instance variable. True False --CORRECT ANSWER--False By default, the java.util.Scanner package is automatically imported into all Java programs. True False --CORRECT ANSWER--False Let's do some code analysis, which statement is true? public class Sphere { private double radius; public double x; private double y;

DO NOT COPY

The run() method someClass. If there are multiple main () methods, that one written first to be called. The someClass method. JVM picks and chooses based on which class was built first. --CORRECT ANSWER--The main() method of someClass. You have seen/written it so many times, what is a class? A class is an encrypted section of computer memory where we host objects. A class is an encrypted section of the hard disk reserved exclusively for hosting object. A class is that part of an object that holds the variables and describes the actions. A class is a description of a kind of object. --CORRECT ANSWER--A class is a description of a kind of object. Technically speaking, what do we call the other name for creating (building) an object? instantiation initialization inheritance assignment --CORRECT ANSWER--instantiation

DO NOT COPY

Let's talk about static variables and methods in Java, What are they? Every object in for a given class has both, otherwise we can't write Java code. Static variables & methods which belong to all objects in real world. Static variables & methods which belong only to selected group of objects in real world. Static variables & methods which are considered a part of class definition, but not of its objects. --CORRECT ANSWER--Static variables & methods which are considered a part of class definition, but not of its objects. I need to calculate the length of a String named sentence and save it back into a variable named size. Let me know which line of code is correct? size = sentence.length() ; size = length.sentence() ; size = length().sentence; size = length( sentence) ; --CORRECT ANSWER--size = sentence.length() ; If your grandma asked you how many objects of a given class may be built in a single Java application? what will be your answer? It depends on how many constructors we have, so basically only one object per constructor.

DO NOT COPY

age and LastName are both considered reference variables --CORRECT ANSWER--age is a primitive variable, and LastName is a reference variable. Here are the declarations again, int age; String LastName; What do you think, how many objects have been created then? Zero— as there is one object reference variable, but no objects yet. One— there is one object reference variable so there must be one object. Two— one for each variable. Two— one for each type. --CORRECT ANSWER--Zero— as there is one object reference variable, but no objects yet. Here are two other declarations, String jerry; String tom = new String("Cat"); Tell me how many objects have been created? zero

DO NOT COPY

one two three --CORRECT ANSWER--one What are the static variables and methods of a class? Variables and methods that form the foundation of each object of that class. Variables and methods that belong to all objects in the computer system. Variables and methods that belong only the objects of that class. Variables and methods that are part of the class definition, but not of its objects. --CORRECT ANSWER--Variables and methods that are part of the class definition, but not of its objects. What do we technically call "to be or not to be" as in the following: String quote= "to be or not to be"; A String shortcut A String literal A quoted String An optimized String --CORRECT ANSWER--A String literal What value is assigned to a reference variable to show that there is no object?

DO NOT COPY

The main() method must be the only static method in a program. --CORRECT ANSWER--It is where the Java interpreter starts the whole program running. Hiding the details of an object from the other parts of code? What do we call this? Obfustication Data Mining Compilation Encapsulation --CORRECT ANSWER--Encapsulation Do you remember when we talked about formal vs. actual parameters. Please say Yes! I can hear you, then what is an actual parameter? It is basically the variable name and type used in a method signature to save the value that is passed into a method by the caller. The value that is actually getting passed into a method by the caller. A primitive variable we to control a counting loop. It is the return value of a method. --CORRECT ANSWER--The value that is actually getting passed into a method by the caller.

DO NOT COPY

What type of parameter passing is used by Java? Call by value. Call by object. Call by invocation. Call by main method --CORRECT ANSWER--Call by value. I know you love the subject of objects and reference variables so much, it will be the gathering subject on the Thanksgiving table. How many references can there be to a single object? Only one. Two: one in a caller and one in the called method. Three: the original reference, and one reference each for a formal and an actual parameter. There can be any number of references, held in any number of variables and parameters (as long as they are of the correct type.) --CORRECT ANSWER-- There can be any number of references, held in any number of variables and parameters (as long as they are of the correct type.) Can a static method call other static methods of the class? No, there is only one static method in a class.

DO NOT COPY

Two or more methods in a class may have the same name, as long as this is different. their return values their access specifier their signatures their memory address --CORRECT ANSWER--their signatures If you write this method for a class, Java will automatically call it any time you concatenate an object of the class with a string. toString plusString stringConvert concatString --CORRECT ANSWER--toString To prevent a class from being instantiated, _____________________ don't use any modifiers on the constructor. use the public modifier on the constructor use the private modifier on the constructor

DO NOT COPY

use the static modifier on the constructor. --CORRECT ANSWER--use the private modifier on the constructor The signature of a method consists of ____________. method name method name and parameter list return type, method name, and parameter list parameter list --CORRECT ANSWER--method name and parameter list Which of the following statements are false? Multiple constructors can't be defined in a class. Constructors do have a return type, for example void. Constructors are invoked without using the new operator when an object is created. All the above --CORRECT ANSWER--All the above A method cannot return a reference to an object. True False --CORRECT ANSWER--False

DO NOT COPY