Reg No:
No Expression Value Type
CS 234 Test-Version 1 (vii) 10<<2+3>>1
(vii)-5+2&7
Qn 1:Answer Tor F forthe following: (ix) 3 ==2?true:3 >2?false:true
No Question Answer
(x) 1.5+2.0f-3.0d
(ü) A subclass can override a superclass method with a On 3: Consider the following code snippet.
different return type For each value of the
variablekey, what is thevalue of result after
(ii) A constructor can be declared asfinal the code executes?
Fill in the correct value in the table.
(ii) If a class is declared final, it cannot be extended int result = 1;
(iv) Allbitwise operations are carried out with the same switch (key)
level of precedence inJava case 1: key result
result += 5; 1
(v) A static method can call a non-static method directly case 2:
2
A private member of a class can result *= 3;
(vi) be accessedby all
methodsin the samepackage break; 3
case 3:
4
(vii) Autoboxing allows automatic conversion between result -- 8;
case 4: 5
primitive types andtheir corresponding wrapper
classes result *= 2;
break;
(vii) An individual arrayelement from an 7
array of type int, case 5:
when passed toamethod is passed by value result += 1; 8
case 6:
(ix) Method overloading 9
is determined based on the result *= 4;
method signature
break;
(X default:
The default value of a local variable is null
result t= 7;
Qn 2: What dothefollowing Java expressionsevaluate? an If
expression does not compileor causes an exception at runtime, Qn 4: Consider thefollowing code tragment. Suppose the
put an X in both columns. statement int x=10; is put into ene of the ten designated
No locations. What will the value of De at the end
Expression Value Type X of the program?
(0) 5+3*2-412 public class BaseClass {
10 %3 + 4*2-1
I Location 1
(i)
protected int x = 5; he
(ii) (double) 5/2+3 I/Location 2
(iv) 2+ "2" +3 public BaseClass() {
1/ Location 3
5>4? 2+3:2-3
(vi) 5&3|4^2 1/Location 4
{
public void baseMethod()
Line Output
1/ Location 5 m = m * 2;
[Link] println ("Basemethod" ; )
.
(ii)
public static void (String[]args)
main
//Location 6 Value of x
(ii)
int[] a = (2, 3, 4);
(iv)
Location 1 int k = 5;
17 Location 7 f(a, k);
public class DerivedClass extends BaseClass
Location 2
Location3
[Link](k) //
[Link]
; ;()
(a[e]) // (ii)
(v)
(vi)
{ Location 4 [Link] );
(a[1] // (iit) (vi)
I/ Location 8 [Link](a[2]); (iv)/ (viii)
public void someMethod() { Location 5 h(a, k);
1/ Location 9 Location 6 [Link](k); (V) 7 Return
value of
[Link](x); [Link](a[e]); // (vi)
// Location 19 Location 7
[Link](a [1]); // (vii) gla, 6.0)
Location 8 [Link] (a [2]); // (viii) Value of
} Location 9 m after
public class Q6 { } f(a, k)
public static void main(String[] args) { Location 10
DerivedClass obj = new DerivedClass( Qn 6: The isValid Date() function takes three
integer arguments representing day,month, and year, and returns
[Link] ();
true ifthey forma valid date in the Gregorian calendar; otherwise,
it returns false. For example, isValidDate(31, 12,2020) returns
true, but isValid Date(31, 4, 2020) returns false. Complete the
Qn 5: Consider the following program. Give the output of this following implementation of isValidDate() with the correct
program for each indicated line in the provided table. (e.g. month > 12) [hint: there is a function
expression
public class PassByValueAndScopeQ t isLeapYear(year)which can be used to check fora leap year]
public static void f(int [] a, int m) { public static boolean isValidDate(int day, int month, int year
double[]b= g(a, 6.0);
a[e] = a[]*m;
){ Expression
if ( 1 ) return false;
a[2] = (int) (b[e] + b[1]);
=m+ 5; if (2 ) return false; 1
m
if (3 ) return false;
2
if ( 4 ) return false;
if ( 5 ) return false; 3
g(int[] a, double x) { if 6)
( return false; 4
public static double[
b=
1
if ( 7 ) return false;
5
double[] new
b[Ø] = a[0] + X,
double[2];
if ( 8) return true;
if ( 9 ) return true; 6
b[1] = a[1] + X;
if ( 1e ) return true; 7
return b;
return false;
public static vosd h(int [] a, int m) {
a[1] = 10
a[1] m;
Qn 7: Assume that the variables s and t are initialized as follows:
String s=
"ABABABABAB"; String t=
"BABABABABA".For
each given expression, provide the expected output or an error if
that is the case.
Expression Output
[Link]() == [Link]()
[Link](1, 2)
2) [Link](2, 3)
[Link](1,
[Link] (1, 2) =- [Link](2, 3)
[Link](1, 2).substring(2, 3)
(s + "A").equals ("A" +t)
[Link] (1)
[Link](4). charAt (1)
[Link] (0) == [Link] ([Link]()
)
[Link]('B')