1) int value = 24;
int divisor = 5;
value % divisor is
a) 4
b) 1
c) 3
d) 0
e) 2
2) int value = 45;
int divisor = 4;
What is the result of value / divisor?
a) 12
b) 11.25
c) 11
d) 10
3) Assume:
int x[][] = {{ 1, 2 }, { 3, 4, 5 }, { 4, 5, 4, 9 }};
What are the values of?
x.length?
x[ 0 ].length?
x[ 1 ].length?
x[ 2 ].length?
4) A class method can be overloaded by changing the number of arguments.
a) True
b) false
5) A class method can be overloaded by changing the return type.
a) True
b) False
6) A while loop will execute at least once?
a) True
b) false
7) A method is invoked by
a) writing the name of the method followed by a colon and the name of the calling object
b) writing the name of the calling object, followed by a dot, followed by the name of the method and a list of values in parentheses
c) writing the name of the calling object followed by a dot and a list of values in parentheses
d) listing the name of the calling object and the name of the method inside parentheses
1] value % divisor is 4. so option a.
2] value / divisor is 11. so option c.
3] x.length is 3, x[0].length is 2, x[1].length is 3, x[2].length is 4
4] A class method can be overloaded by changing the number of arguments is True. option a.
5] A class method can be overloaded by changing the return type is False. option b.
6] A while loop will execute at least once is false. so option b.
7] A method is invoked by writing the name of the calling object, followed by a dot, followed by the name of the method and a list of values in parentheses. for ex: obj.sum(2, 4). so option b.
Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array double[10]; c. charl charArray "Computer Science"; None of the above Analyze the following code: class Test public static void main(Stringl] args) System.out.println(xMethod(10); public static int xMethod(int n) System.out.println("int"); return n; public static long xMethod(long n) System.out.,println("long"); return n The program displays int followed by 10 The program displays long followed by 10. The program does not compile. None of the above. tions 3-4 are...
JAVA 5) What is the output of the following code? int a = 70; boolean b = false; if(a >= 70) { System.out.print(1); if(b==true) { System.out.print(2); } } else { System.out.print(3); if(b==false) { System.out.print(4); } } System.out.print(5); 6) What is the output of the code above using these initial values? int a = 43; boolean b = false; 7) The following method is SYNTACTICALLY correct (meaning it will compile). True or false? public boolean method() { int value = 5;...
Write a class named Month. The class should have an int field named monthNumber that holds the number of the month. For example. January would be 1. February would be 2. and so forth. In addition, provide the following methods A no-arg constructor that sets the monthNumber field to 1 A constructor that accepts the number of the month as an argument. It should set the monthNumber field to the value passed as the argument. If a value less than...
In Java Which of the following statements declares Salaried as a subclass of payType? Public class Salaried implements PayType Public class Salaried derivedFrom(payType) Public class PayType derives Salaried Public class Salaried extends PayType If a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method. False True When a subclass overloads a superclass method………. Only the subclass method may be called with a subclass object Only the superclass method...
1). The result of Java expression 5*7>3*(5+2) && 3*5-4<6 is ____ a. 35>35&&9<6 b. true && false c. false d. False (2). You save text files containing Java language source code using the file extension___ a. .java b. .class c. .txt d. .src (3). Which of the following is not a primitive data type in the Java programming language? a. boolean b. byte c. int d. Point (4). Given the Java statement int[][] vari = new int[5][7]; the value...
Question 22 4 pts In the statement: Int'. p and q are pointer variables. True False D Question 23 4 pts If a user-defined class object that uses mathematical operators to pass to the template function, the class must contain code for the primitive data types the constructor the overloaded operators the try/catch blocks Question 24 4 pts Afriend function is a function that is not part of a class but has access to the class's private members as well...
1. What will be the value of x after the following code is executed? int x = 10, y = 20; while (y < 100) { x += y; } A. 90 B. 110 C. 210 D. This is an infinite loop 2. If a superclass has constructor(s): A. then its subclass must initialize the superclass fields (attributes). B. then its subclass must call one of the constructors that the superclass does have. C. then its subclass does not inherit...
true or false in JAVA 1) A literal value is a value that is typed directly into the code, such as 10, 14.6, or "Bob". 2) Local variables can only be accessed from within the block in which they are defined. 3) All variables must be declared before they can be used. 4) If a method returns nothing, its return type should be null. 5) A method with an int parameter can be invoked with a String argument. 6) A...
JAVA QUESTION 1 The value returned by a value-returning method can be saved for further calculation in the program. True False QUESTION 2 To use a predefined method you must know the code in the body of the method. True False QUESTION 3 A formal parameter is a variable declared in the method heading (ie. it's signature). True False QUESTION 4 A local identifier is an identifier that is declared within a method or block and that is visible only...
Exercise 11 - in Java please complete the following:
For this exercise, you need to work on your own. In this exercise you will write the implementation of the pre-written implementation of the class CAR. The class CAR has the following data and methods listed below: . Data fields: A String model that stores the car model, and an int year that stores the year the car was built. . Default constructor . Overloaded constructor that passes values for both...