0% found this document useful (0 votes)
4 views18 pages

Basic Java Test for RPSC Programmer Exam

Uploaded by

kj2jbxr7pc
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views18 pages

Basic Java Test for RPSC Programmer Exam

Uploaded by

kj2jbxr7pc
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Mockwarriors

Topic Test – Basic Java


Specially Design For RPSC Programmer Exam
Time – 15 Minutes. Telegram- @Mockwarriors_itexam [Link]

Q1. What is the output of the following code snippet?


int x = 20;
int y = 20;
int z = x++ + ++y;
[Link](z);
a) 41
b) 42
c) 43
d) 44

Q2. Which of the following is not a valid identifier in Java?


a) $coder
b) _ programmer
c) 123programmer
d) programmer_123

Q3. Find the output of the following code:


public static void main(String args[])
{
int i = -1;
while (i < 5) {
[Link](i + " ");
i++;
}
}
a) -1 0 1 2 3 4
b) -1 1 2 3 4 5
c) 0 1 2 3 4 5
d) -1 2 3 4 5 6

Q4. which is the first line (if any) that causes a compilation error ?
public static void main(String args[])
{
char c;
int i;
c = 'A'; // 1
i = c; //2
c = i + 1; //3
c++; //
}
a) The line labeled 1.
b) The line labeled 2.
c) The line labeled 3.
d) The line labeled 4.

Q5. Which of these assignments are Not Valid ?


a) short s = 28;
b) float f = 2.3;
c) int I = '1';
d) byte b = 12;

Q6. Find the output of the following code:


public static void main(String args[])
{
byte x = 3;
x = (byte)~x;
[Link](x);
}
a) -1
b) -3
c) +3
d) -4

Q7. Find the output of the following code:


public static void main(String args[])
{
int x,y;
x = 1 & 8;
y = 3 ^ 5;
[Link](x + " " + y);
}
a) 0 6
b) 6 0
c) 8 0
d) 0 8

Q8. Find the output of the following code:


public static void main(String args[])
{
int x, y;
x = 5 >> 2;
y = x >>> 2;
[Link](y);
}
a) 1
b) 2
c) 3
d) 0

Q9. Find the output of the following code:


public static void main(String args[])
{
[Link](1/9 + 5/2 + 0.1);
}
a) 1.1
b) 2.1
c) 3.1
d) 3

Q10. Find the output of the following code:


public static void main(String args[])
{
int i = 5;
boolean t = true;
boolean f = false, b;
b = (t | ((i++) == 0));
b = (f | ((i+=2) > 0));
[Link](i);
}
a) 6
b) 7s
c) 8
d) 9

Ansker Key will Be updated Here


Telegram- @Mockwarriors_itexam
[Link]
Mockwarriors
Answer-Key – Basic Java
Specially Design For RPSC Programmer Exam
Answer Key Telegram- @Mockwarriors_itexam [Link]

Q1 A
Q2 C
Q3 A
Q4 C
Q5 B
Q6 D
Q7 A
Q8 D
Q9 B
Q10 C

Click Here To View Question Paper


Telegram- @Mockwarriors_itexam
[Link]
Mockwarriors
Topic Test – Basic Java Test 2
Specially Design For RPSC Programmer Exam
Time – 15 Minutes. Telegram- @Mockwarriors_itexam [Link]

Q1. What is the output of the following code:


class Mockwarriors{
public static void main(String[] args)
{
int a = 10;
int b = 20;
if (++a <= 10 && --b < 20) {}
[Link]("a = " + a + " b = " + b);
a = 10;
b = 20;
if (++a <= 10 & --b < 20) {}
[Link]("a = " + a + " b = " + b);
}
}
a) a = 11 b = 20
a = 12 b = 18
b) a = 11 b = 20
a = 11 b = 19
c) a = 10 b = 20
a = 11 b = 19
d) a = 11 b = 20
a = 11 b = 18

Q2. What is the output of the following code:


class Mockwarriors{

public static void main(String[] args)


{
int a = 10;
int b = 20;
if (++a <= 10 || --b < 20) {}
[Link]("a = " + a + " b = " + b);
a = 10;
b = 20;
if (++a <= 10 | --b < 20) {}
[Link]("a = " + a + " b = " + b);
}
}
a) a = 11 b = 20
a = 12 b = 18
b) a = 11 b = 20
a = 11 b = 19
c) a = 11 b = 19
a = 11 b = 19
d) a = 11 b = 20
a = 11 b = 18

Q3. What is the output of the following code:


class Mockwarriors {
public static void main(String args[]) {
int[] a = {1, 2, 3, 4, 5, 6};
int i = [Link] - 1;
while (i >= 0) {
[Link](a[i]);
i--;
}
}
}
a) 654321
b) 6543210
c) 123456
d) 0123456

Q4. What is the output of the following code:


class Mockwarriors{
static int x = 10;
public static void main(String[] args)
{
for(int x=0;x<5;x++){}
[Link](x);
}
}
a) 10
b) 012345
c) 12345
d) 123456789

Q5. What is the output of the following code:


class Mockwarriors {
public static void main(String args[]) {
short p=1; // Line 1
short k=0; // Line 2
k=p+1; // Line 3
[Link](k);
}
}
a) 1
b) Error Because of Line 1
c) Error Because of Line 2
d) Error Because of Line 3

Q6. What is the output of the following code:


class Mockwarriors {
public static void main (String args[])
{
for (int i = 0; i < 3; i++)
{
for (int j = 3; j <= 0; j--)
{
if (i == j) continue;
[Link](i + " " + j);
}
}
}
}
a) blank
b) 0
c) 321
d) 123

Q7. What is the output of the following code:


class Mockwarriors{
public static void main(String args[])
{
boolean x = true;
int a;
if(x) a = x ? 1: 2;
else a = x ? 3: 4;
[Link](a);
}
}
a) 1
b) 2
c) 3
d) 4

Q8. Which of the following is not legal identifiers?


a) _4_
b) @name
c) getSize
d) $

Q9. Which of the following for loop declaration is not valid?


a) for ( int j = 7; j <= 77; j += 7 )

b) for ( int j = 20; j >= 2; --j )


c) for ( int j = 2; j <= 20; j = 2* j )

d) for ( int j = 99; j >= 0; j / 9 )

Q10. What is the output of the following code:


class Mockwarriors{
public static void main(String args[])
{
int x = 1;
int y = 2;
int z = x++;
int a = --y;
int b = z--;
b += ++z;
int answ = x>a?y>b?y:b:x>z?x:z;
[Link](answ);
}
}
a) 1
b) 2
c) 3
d) 4

Ansker Key will Be updated Here


Telegram- @Mockwarriors_itexam
[Link]
Mockwarriors
Answer-Key – Basic Java Test 2
Specially Design For RPSC Programmer Exam
Answer Key Telegram- @Mockwarriors_itexam [Link]

Q1 B
Q2 C
Q3 A
Q4 A
Q5 D
Q6 A
Q7 A
Q8 B
Q9 D
Q10 B

Click Here To View Question Paper


Telegram- @Mockwarriors_itexam
[Link]
Mockwarriors
Topic Test – Basic Java Test 3
Specially Design For RPSC Programmer Exam
Time – 15 Minutes. Telegram- @Mockwarriors_itexam [Link]

Q1. What is the default value of a char in Java?


a) '0'
b) ' '
c) '\u0000'
d) '\uffff'

Q2. Find the output:


class A {
int i;
}
class B extends A {
int j;
void display()
{
super.i = j + 1;
[Link](j + " " + i);
}
}
class inheritance
{
public static void main(String args[])
{
B obj = new B();
obj.i = 1;
obj.j = 2;
[Link]();
}
}
a) 2 3
b) 2 4
c) 4 3
d) 1 2

Q3. Redefining the super class method in the subclass is known as __


a) Dynamic Binding
b) Method Overloading
c) Method Overriding
d) None of These

Q4. Which of the following is a valid abstract class?


a) class A { abstract void test() {} }
b) class A { abstract void test(); }
c) abstract class A { abstract void test(); }
d) public class abstract A { abstract void test(); }

Q5. Which of the following declares an abstract method in an abstract Java class?
a) public abstract method();
b) public abstract void method();
c) public void method() {}
d) public void abstract Method();

Q6. Find the output:


class Mockwarriors {
public static void main (String args[])
{
byte x=1;
x+=11;
[Link](x);
}
}
a) 2
b) 12
c) 11
d) Compilation Error

Q7. Error Occurs Because of


class Mockwarriors {
public static void main (String args[])
{
byte x=1;
x+=11; // Line 1
x=x+10; // Line 2
x++; // Line 3
x--; // Line 4
[Link](x);
}
}
a) Line 1 and Line 2
b) Line 3 and Line 4
c) Only Line 2
d) Line 2, Line 3 and Line 4

Q8. Find the output:


class Mockwarriors {
void sum() {
int age=5;
[Link](age);
}
public static void main(String args[]) {
Mockwarriors test = new Mockwarriors();
[Link]();
}
}
a) 1
b) 0
c) 5
d) Compilation Error

Q9. Find the output:


class Mockwarriors {
static int age;
void sum() {
int age=5;
[Link](age);
}
public static void main(String args[]) {
Mockwarriors test = new Mockwarriors();
[Link]();
}
}
a) 1
b) 0
c) 5
d) Compilation Error

Q10. Modulus operator(%) In Java, can be applied to which of these?


a) Both Integers and floating – point numbers
b) Integers
c) Floating – point numbers
d) None of the mentioned

Answer Key will Be updated Here


Telegram- @Mockwarriors_itexam
[Link]
Mockwarriors
Answer-Key – Basic Java Test 3
Specially Design For RPSC Programmer Exam
Answer Key Telegram- @Mockwarriors_itexam [Link]

Q1 C
Q2 A
Q3 C
Q4 C
Q5 B
Q6 B
Q7 C
Q8 C
Q9 C
Q10 A

Click Here To View Question Paper


Telegram- @Mockwarriors_itexam
[Link]
Mockwarriors
Topic Test – Basic Java Test 4
Specially Design For RPSC Programmer Exam
Time – 15 Minutes. Telegram- @Mockwarriors_itexam [Link]

Q1. What is the output of the following code:


class Mockwarriors{
public static void main(String[] args) { int a[][] = new int[3][];
a[1] = new int[]{1,2,3};
a[2] = new int[]{4,5};
[Link](a[1][1]);
}}
a) 1
b) 2
c) 3
d) 4

Q2. What is the output of the following code:


class Warriors{
void sum() {
static int age=5;
[Link](age);
}
public static void main(String args[]) {
Warriors test = new Warriors();
[Link]();
}
}
a) 5
b) 0
c) Compilation Error
d) Runtime Error

Q3. What is the output of the following code:


class Warriors{
void sum() {
int Static=5;
[Link](Static);
}
public static void main(String args[]) {
Warriors test = new Warriors();
[Link]();
}
}
a) 5
b) 0
c) Compilation Error
d) Runtime Error

Q4. What is the output of the following code:


class MockWarriors{
static {
char Char='A';
[Link](Char);
}
{
[Link]("Instance Called");
}
public static void main(String args[]) {
}
}
a) A
b) A
Instance Called
c) Compilation Error
d) Runtime Error

Q5. What is the output of the following code:


class MockWarriors{
static {
String Char="MockWarriors";
[Link](Char);
}
{
[Link]("Join Our Telegram");
}
public static void main(String args[]) {
MockWarriors r= new MockWarriors();
new MockWarriors();
}
}
a) MockWarriors
Join Our Telegram
b) MockWarriors
Join Our Telegram
Join Our Telegram
c) No Output
d) MockWarriors
Join Our Telegram
Join Our Telegram
Join Our Telegram
Q6. What is the output of the following code:
class Warriors{
static {
String $="MockWarriors";
[Link]($);
}
{
[Link]("Join Our Telegram");
}
Warriors(){
[Link]("Channel For More Content");
}
public static void main(String args[]) {
new Warriors();
}
}
a) Error
b) Join Our Telegram
Channel For More Content
c) No Output
d) MockWarriors
Join Our Telegram
Channel For More Content

Q7. What is the output of the following code:


class Warriors{
static {
new Warriors();
String $="MockWarriors";
[Link]($);
}
Warriors(){
[Link]("Join Our Community");
}
public static void main(String args[]) {
}
}
a) Error
b) Join Our Community
MockWarriors
c) MockWarriors
Join Our Community
d) No Output

Telegram- @Mockwarriors_itexam
Q8. What is the output of the following code:
class MockWarriors{
{
[Link]("Finally Joined Our Community");
}
public static void main(String args[]) {
}
}
a) Finally Joined Our Community
b) no output
c) Run Time Error
d) Compilation Error

Q9. Which of the following is a correct method declaration in Java?


a) public int mockWarriors(int a, int b)
b) public mockWarriors(int a, int b): int
c) mockWarriors{int a, int b}
d) mockWarriors[int a, int b]

Q10. Which of the following is a correct method declaration in Java?


1) MockWarriors
2) _mockWarriors
3) 5mockWarriors
4) mockWarriors5

a) Only 2
b) Both 1 and 2
c) Both 1, 2 and 4
d) Only 3

Answer Key will Be updated Here


Telegram- @Mockwarriors_itexam
[Link]
Mockwarriors
Answer-Key – Basic Java Test 4
Specially Design For RPSC Programmer Exam
Answer Key Telegram- @Mockwarriors_itexam [Link]

Q1 B
Q2 C
Q3 A
Q4 A
Q5 B
Q6 D
Q7 B
Q8 B
Q9 A
Q10 C

Telegram- @Mockwarriors_itexam
[Link]

Common questions

Powered by AI

This class causes a compilation error because it defines an abstract method with a body '{}', which abstract methods are not allowed to have. An abstract method must be declared without a body in order to be overridden by subclasses. Making 'void test() {}' concrete by providing an implementation would resolve this confusion .

The '&&' operator performs a short-circuiting logical AND operation. If the first condition '++a <= 10' evaluates to false, the second condition '--b < 20' is not evaluated, as it's unnecessary for determining the overall expression's truth value. If the first condition is true, only then does the second condition check execute. In the context provided, incrementing a before the comparison could change control flow significantly by altering variable states .

The operation '~x' is a bitwise NOT operation which inverts all bits of byte x. For a byte value of 3 (binary: 00000011), applying ~ results in all bits being inverted (binary: 11111100), which corresponds to -4 when interpreted as a signed byte in Java. Casting it back to byte doesn't change this binary value to an unsigned interpretation and thus prints -4 .

The console output would be 'MockWarriors' because Java static blocks are executed as the class is loaded into memory, ensuring that any static initializations and operations such as assignments and prints are undertaken immediately, reflecting the initialized value directly in output .

The expression '1/9' and '5/2' are integer divisions. In Java, integer division discards the decimal part, thus '1/9' results in 0 and '5/2' results in 2. The rest, '0 + 2 + 0.1', results in 2.1. Since floating-point arithmetic adds the '.1' as a double to the integer results, the final float result becomes 2.1 .

In Java, implicit conversion is not bi-directional between char and int. During the assignment 'c = i + 1;', the expression 'i + 1' is of type int, which cannot be implicitly converted to a char, leading to a compilation error without an explicit cast, due to potential loss of precision and differences in byte size .

When using the post-decrement 'z--', the current value of z is used in any expression, and then it's decremented by 1 after its value has been retrieved. For 'int z = x++; int b = z--; b += ++z;', initially z is derived from x, where z = 1 (since x is post-incremented), and then z is decremented in b = z-- making b = 1 before z becomes 0. In 'b += ++z;', z is pre-incremented to 1, hence b becomes 2 once increment is added .

This loop is considered a syntax error because the increment/decrement part of the for loop should result in a boolean condition or mutation of the loop control variable for the loop to end; 'j / 9' doesn't change the value of j nor does it evaluate a boolean condition. Instead, it should involve an operation where j is assigned a new computed value, such as 'j--' .

The expression results in 42. Initially, x is 20 and y is 20. The post-increment 'x++' will use x as 20 but then increment x to 21. The pre-increment '++y' will first increment y to 21 and use it in the expression, so 20 (initial x) + 21 (incremented y) equals 41. Since x is used before being incremented completely in the expression, the direct calculation would yield 41, which is incremented as per the operation outputs .

The identifier '123programmer' is invalid in Java because an identifier cannot start with a digit. Java identifiers must start with a letter, underscore (_), or dollar sign ($).

You might also like