Java Test 3 - Google Forms
Java Test 3 - Google Forms
2. What is the output of the below Java program with two classes? //Testing1.java * A) bingo
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);
}
}
T1 before: 4, T1 After :4
T1 before: 2, T1 After :4
Compiler error
T1 before: 2, T1 After :2
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; }
}
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
D) Compiler error
A) Address value
B) Variable value
C) Hash code
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. }
C) Compiler error
D) None
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 }
C) NullPointerException
D) Compiler error
17. In Java, local variables are stored in __ memory and instance variables are *
stored in ___ memory.
A) Stack, Stack
B) Heap, Heap
C) Stack, Heap
D) Heap, Stack
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
A) Default constructor
B) User-defined constructor
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); //
} }
A and B
A, B, C
Forms
https://docs.google.com/forms/d/138XQkfX0SEfXRWGWrqYLLcyT0Hdrre038HKizqueHko/edit 17/17