Title | Java Programming Final Exam |
---|---|
Course | Java Programming |
Institution | Valencia College |
Pages | 9 |
File Size | 226.6 KB |
File Type | |
Total Downloads | 69 |
Total Views | 152 |
This is the Final Exam in Java Programming. It has all the questions and all of the correct answers....
Final Exam Started: Apr 22 at 8:49pm
Quiz Instrucons Multiple choice. Please only select one answer per question.
Question 1
5 pts
Which of the following is NOT a legal identifier (variable/method/class names) in Java? Choose 1 that will not compile.
WhatALongClassNameYouHave what_a_variable 2variable _3_ $another$var
Question 2
5 pts
What is the value of the variable intResult, given: int a = 3, b = 2, c = 10, intResult; intResult = c % a*b;
2 6 6.6 10
Question 3 what will be printed out when the following code executes? choose one int i = 1; switch(i){ case 0:
5 pts
System.out.println("zero"); break; case 1: System.out.println("one"); case 2: System.out.println("two"); default: System.out.println("default"); }
one one, default one, two, default default nothing will be printed
Question 4
5 pts
Which of the following lines will compile without warning or error?
float f = 1.3; char c = "a"; byte b = 257; boolean b = null; int i = 10;
Question 5 What is the value of the following Java expression, given: int a = 3, b = 5, c = 4, d = 6; !(a < b) || c > d
5 pts
true false 0 1
Question 6
5 pts
What would be the output from this code fragment? int x = 1, y = 8, z = 5; if(x < 7){ if(y < 5){ System.out.println("message one"); }else { System.out.println("message two"); } }else if(z > 5){ System.out.println("message three"); }else{ System.out.println("message four"); }
message one message two message three message four
Question 7 What is the definition of an overloaded method?
Method that has been executed too many times Method that takes a long time to run Methods with the same name, but different parameter lists Method with several return values
5 pts
Question 8
5 pts
Which of the following is a reason to enforce access to instance variables via getters and setters?
Encrustation Encapsulation Limitation Aggregation
Question 9
5 pts
What are the initial values of the variables tracks and time? public class Test{ private int tracks; public void mark(int whichTrack){ double time; System.out.println(whichTrack); } }
tracks is 0, time is uninitialized tracks is uninitialized, time is 0.0 tracks is 0, time is 0.0 tracks is uninitialized, time is uninitialized
Question 10 Given the classes: public class AA{ double doSomething(int c, int d){ }
5 pts
//Location A } public class BB extends AA{ //Location B }
double doSomething(int c, int d) Location A double doSomething(int c, int d) Location B double doSomething(double a) Location A double doSomething(float a) Location B
Question 11
5 pts
What would be a valid constructor for the following class? public class Test{ }
Constructor Test(){} Test(){} TestA(){} void Test(){}
Question 12 Which statement is true?
Overriding is just another term for overloading Overloading only can be done within an inheritance structure Overriding only can be done within an inheritance structure You can override a constructor
5 pts
Question 13
5 pts
Which statement is false?
You can invoke a nonstatic method from within a static method You can invoke a nonstatic method from within a non-static method You can invoke a static method from within a static method None of the above
Question 14
5 pts
What is the value of x[3] after execution of this code fragment? int x[] = {3,6,4,10); x[3] -= x[1] % x[2];
1 8 9 12
Question 15 What is the output of the following code? public class Test{ public static void main(String[] args){ double sum = 0.0; double b[] = {2.0, 1.0, 3.0}; for(int k = 0; k < b.length - 1; k++){ sum += b[k]; } System.out.println("The sum is " + sum);
5 pts
} }
1.0 2.0 3.0 4.0
Question 16
5 pts
After execution of the code fragment below, what is the value of the variable x? int b[] = {4,6,7}; int x = ++b[1] + b[2]++;
12 13 14 15
Question 17 What is the output of running the following code? public class Test{ public static void main(String[] args){ int b = 5; int ar[] = {5, 4, 3, 2}; double val = myMethod(b, ar); System.out.println(val + "," + ar[2] + "," + b); } public static double myMethod(double b, int arr[]){ b -= 1.0; arr[2] = (int)(arr[1] * b); return b; } }
5 pts
4.0, 16, 5 4.0, 16, 4 4.0, 16, -1 4, 3, 4 4, 20, 5
Question 18
5 pts
Which is following is false about constructors
Constructors are not needed Constructors are there by default. Even if you dont' see it. Constructors can be overloaded All Constructors are public
Question 19
5 pts
What statement is to describe class B being a subclass (child) of class A?
class B implements A class B extends A class A implements B class A extends B
Question 20
What is the difference between a while loop and a do-while loop? No difference While loop tests condition after execution. Do-While loop tests condition before execution
5 pts
While loop tests condition before execution. Do-While loop tests condition after execution While loop is guaranteed to run at least once. Do-While is not guaranteed to run at least once.
Quiz saved at 8:51pm
Submit Quiz...