0% found this document useful (0 votes)
65 views

Java Test 3 - Google Forms

Uploaded by

Gomathy
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)
65 views

Java Test 3 - Google Forms

Uploaded by

Gomathy
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
You are on page 1/ 5

07/10/2024, 10:29 Java Test 3 07/10/2024, 10:29 Java Test 3

3. What is the output of the below Java program? *


//bingo.java file
Java Test 3 public class Hello
online test on OOP concepts and methods {
public static void main(String[] args)
* Indicates required question
{
System.out.println("BINGO");
1. Batch No * }
}

Mark only one oval.

2. What is the output of the below Java program with two classes? //Testing1.java * A) bingo

public class Example B) BINGO


{ C) Compiler error

D) None
}
public class Testing1
{
public static void main(String[] args) 4. What is the output of the below java class? *
{ class Fox
System.out.println("Hello Boss.!"); {
} int legs = 2;
} }
class Testing2
Mark only one oval.
{
A) Hello Boss.! public static void main(String[] args)
{
B) No Output
Fox t1 = new Fox();
C) Compiler error
System.out.println("T1 before: " + t1.legs);
D) None of the above t1.legs = 4;
System.out.println("T1 After: " + t1.legs);
}
}

Mark only one oval.

T1 before: 4, T1 After :4

T1 before: 2, T1 After :4

Compiler error

T1 before: 2, T1 After :2

https://docs.google.com/forms/d/138XQkfX0SEfXRWGWrqYLLcyT0Hdrre038HKizqueHko/edit 1/17 https://docs.google.com/forms/d/138XQkfX0SEfXRWGWrqYLLcyT0Hdrre038HKizqueHko/edit 2/17

07/10/2024, 10:29 Java Test 3 07/10/2024, 10:29 Java Test 3

5. A primitive variable is passed from one method to another method by ___ * 7. What is the output of the below Java program that passes an object to another *
in Java. method?
class Food
Mark only one oval.
{
A) Pass by value int items;
int show()
B) Pass by reference
{return items;}
}

6. An object or a primitive value that is received in a method from another * class Testing9
method is called ___ in Java. (Argument / Parameter) {
public static void main(String[] args)
Mark only one oval. {
Food f = new Food();
A) Argument
f.items = 5;
B) Parameter System.out.println("Items Before = " + f.show());
change(f);
System.out.println("Items After = " + f.show());
}
static void change(Food foo)
{ foo.items = 10; }
}

Mark only one oval.

Items Before = 10 Items After = 10

Items Before = 5 Items After = 5

Items Before = 5 Items After = 10

Items Before = 5 Items After = 10

https://docs.google.com/forms/d/138XQkfX0SEfXRWGWrqYLLcyT0Hdrre038HKizqueHko/edit 3/17 https://docs.google.com/forms/d/138XQkfX0SEfXRWGWrqYLLcyT0Hdrre038HKizqueHko/edit 4/17


07/10/2024, 10:29 Java Test 3 07/10/2024, 10:29 Java Test 3

8. What is the output of the below Java program that passes primitive values? * 10. What is the output of the below Java program? *
class Testing10 class Cricket
{ { int runs; }
int rats = 5;
class Testing19
public static void main(String[] args) {
{ public static void main(String[] args)
Testing10 t1 = new Testing10(); {
System.out.println("Rats Before = " + t1.rats); Cricket c1 = new Cricket();
modify(t1.rats); c1.runs = 250;
System.out.println("Rats After = " + t1.rats); Cricket c2;
} c2 = c1;
static void modify(int r) c2.runs = 300;
{ r = 20; } System.out.println("Runs= " + c1.runs);
} }
}
Mark only one oval.
Mark only one oval.
Rats Before = 5 Rats After = 5

Rats Before =20 Rats After = 20 A) Runs= 0

Rats Before = 5 Rats After = 20 B) Runs= 250

Rats Before =20 Rats After = 5 C) Runs= 300

D) Compiler error

9. In Java Pass by reference ___ is passed even if you are passing a *


reference to an object.

Mark only one oval.

A) Address value

B) Variable value

C) Hash code

D) None of the above

https://docs.google.com/forms/d/138XQkfX0SEfXRWGWrqYLLcyT0Hdrre038HKizqueHko/edit 5/17 https://docs.google.com/forms/d/138XQkfX0SEfXRWGWrqYLLcyT0Hdrre038HKizqueHko/edit 6/17

07/10/2024, 10:29 Java Test 3 07/10/2024, 10:29 Java Test 3

11. What is the output of the below Java program? * 13. Java method signature is a combination of ___. *
class Wordpress
Mark only one oval.
{ int posts; }
class Testing20 A) Return type
{
B) Method name
public static void main(String[] args)
{ C) Argument List
Wordpress wp1 = new Wordpress(); D) All the above
wp1.posts = 25; B and C
Wordpress wp2 = wp1;
wp1 = null;
System.out.println("Posts=" + wp2.posts);
} 14. What is the output of the below Java program with an empty return statement? *
} public class TestingMethods2
{
Mark only one oval.
void show()
A) Posts=25
{
System.out.println("SHOW Method..");
B) Posts=0
return;
C) Posts=null }
D) Runtime exception occurs public static void main(String[] args)
{
TestingMethods2 t2 = new TestingMethods2();
t2.show();
12. State TRUE or FALSE. A Java method can have the same name as the class * }
name. }

Mark only one oval. Mark only one oval.

A) TRUE A) SHOW Method..


B) FALSE B) No output

C) Compiler error

D) None

https://docs.google.com/forms/d/138XQkfX0SEfXRWGWrqYLLcyT0Hdrre038HKizqueHko/edit 7/17 https://docs.google.com/forms/d/138XQkfX0SEfXRWGWrqYLLcyT0Hdrre038HKizqueHko/edit 8/17


07/10/2024, 10:29 Java Test 3 07/10/2024, 10:29 Java Test 3

15. A "this" operator used inside a Java method refers to ___ variable. * 18. What is the output of the below Java program? *
class Road
Mark only one oval.
{
A) Global variable static void show()
{
B) Method local variable
System.out.println("Inside static method.");
C) Instance variable }
D) None }

public class TestingMethods10


{
16. What is the output of the below Java program? * public static void main(String[] args)
public class TestingMethods5 {
{ Road.show();
public static void main(String[] args) }
{ }
int localVariable;
System.out.println(localVariable); Mark only one oval.
}
A) Inside static method.
}
B) empty message
Mark only one oval.
C) Compiler error
A) 0 D) Runtime error / exception
B) garbage value

C) NullPointerException

D) Compiler error

17. In Java, local variables are stored in __ memory and instance variables are *
stored in ___ memory.

Mark only one oval.

A) Stack, Stack

B) Heap, Heap

C) Stack, Heap

D) Heap, Stack

https://docs.google.com/forms/d/138XQkfX0SEfXRWGWrqYLLcyT0Hdrre038HKizqueHko/edit 9/17 https://docs.google.com/forms/d/138XQkfX0SEfXRWGWrqYLLcyT0Hdrre038HKizqueHko/edit 10/17

07/10/2024, 10:29 Java Test 3 07/10/2024, 10:29 Java Test 3

19. What is the output of the Java program with static variables? * 21. What is the output of the below Java program? *
public class TestingMethods6 public class TestingConstructor
{ {
static int cats=25; void TestingConstructor()
public static void main(String[] args) {
{ System.out.println("Amsterdam");
TestingMethods6 t6 = new TestingMethods6(); }
System.out.println("t6 BIRDS before=" + t6.cats);
TestingMethods6 t7 = new TestingMethods6(); TestingConstructor()
t7.cats = 10; {
System.out.println("t6 BIRDS after=" + t6.cats); System.out.println("Antarctica");
} }
}
public static void main(String[] args)
Mark only one oval.
{
t6 BIRDS before=25 t6 BIRDS after=25 TestingConstructor tc = new TestingConstructor();
}
t6 BIRDS before=25 t6 BIRDS after=10
}
t6 BIRDS before=25 t6 BIRDS after=0
Mark only one oval.
None

A) Antarctica

B) Amsterdam
20. In Java, a constructor with no parameters or no arguments is called ___ * C) No output
constructor.
D) Compiler error

Mark only one oval.

A) Default constructor

B) User-defined constructor

https://docs.google.com/forms/d/138XQkfX0SEfXRWGWrqYLLcyT0Hdrre038HKizqueHko/edit 11/17 https://docs.google.com/forms/d/138XQkfX0SEfXRWGWrqYLLcyT0Hdrre038HKizqueHko/edit 12/17


07/10/2024, 10:29 Java Test 3 07/10/2024, 10:29 Java Test 3

22. What is the output of the below Java program with overloaded constructors? * 23. Choose the correct way of calling the second constructor from the first *
public class Constructor3 constructor in the below code options.
{ A)
int birds=10; Constructor5()
Constructor3() {
{ int a=30;
this(20); this('A');
} }
Constructor3(int birds) Constructor5(char c)
{ {
System.out.println("Birds=" + birds); //
} }

public static void main(String[] args) B)


{ Constructor5()
Constructor3 con = new Constructor3(); {
} int a=30;
} this('A');
System.out.println("Success");
Mark only one oval.
}
A) Birds=0 Constructor5(char c)
{
B) Birds=10
//
C) Birds=20 }
D) Compiler error
C)
Constructor5()
{
this('A');
System.out.println("Success");
}
Constructor5(char c)
{
//
}

D) All the above

Mark only one oval.

A and B

A, B, C

https://docs.google.com/forms/d/138XQkfX0SEfXRWGWrqYLLcyT0Hdrre038HKizqueHko/edit 13/17 https://docs.google.com/forms/d/138XQkfX0SEfXRWGWrqYLLcyT0Hdrre038HKizqueHko/edit 14/17

07/10/2024, 10:29 Java Test 3 07/10/2024, 10:29 Java Test 3

All are correct


25. What is the output of the below Java program with multiple methods? *
public class MethodOverloading1
{
24. What is the output of the below Java program with many constructors? * void show(int a, char b)
public class Constructor8 {
{ System.out.println("KING KONG");
Constructor8(boolean a) }
{
System.out.println("MODEM="+ a ); void show(char a, int b)
} {
Constructor8(float a) System.out.println("JIM JAM");
{ }
System.out.println("ROUTER=" + a);
} public static void main(String[] args)
public static void main(String[] args) {
{ MethodOverloading1 m = new MethodOverloading1();
Constructor8 con1 = new Constructor8(50); m.show(10, 'A');
Constructor8 con2 = new Constructor8(false); m.show('B', 10);
} }
} }

Mark only one oval. Mark only one oval.

ROUTER=50.0 MODEM=false JIM JAM JIM JAM

ROUTER=50 MODEM=false KING KONG KING KONG

Compile error JIM JAM KING KONG

None compiler error

This content is neither created nor endorsed by Google.

Forms

https://docs.google.com/forms/d/138XQkfX0SEfXRWGWrqYLLcyT0Hdrre038HKizqueHko/edit 15/17 https://docs.google.com/forms/d/138XQkfX0SEfXRWGWrqYLLcyT0Hdrre038HKizqueHko/edit 16/17


07/10/2024, 10:29 Java Test 3

https://docs.google.com/forms/d/138XQkfX0SEfXRWGWrqYLLcyT0Hdrre038HKizqueHko/edit 17/17

You might also like