Programming in Java - Output Prediction

Quiz
•
Computers
•
University
•
Medium
Lakshmi Anand
Used 4+ times
FREE Resource
5 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Predict the output:
class Test {
protected int x=10, y=10;
}
class Main {
public static void main(String args[]) {
Test t = new Test();
System.out.println(t.x + " " + t.y);
}
}
Garbage Value
0 0
10 10
5 5
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Predict the output:
class Test {
private static int x;
public static void main(String args[]) {
System.out.println(fun());
}
static int fun() {
return ++x;
}
}
1
Error
0
Garbage Value
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Predict the output:
class Base {
public void Print()
{
System.out.println("Base");
}
}
class Derived extends Base {
public void Print()
{
System.out.println("Derived");
}
}
class Main {
public static void DoPrint(Base o)
{
o.Print();
}
public static void main(String[] args)
{
Base x = new Base();
Base y = new Derived();
Derived z = new Derived();
DoPrint(x);
DoPrint(y);
DoPrint(z);
}
}
Base
Derived
Base
Base
Derived
Derived
Derived
Base
Derived
Derived
Derived
Base
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Predict the output:
class Test {
int x = 10;
public static void main(String[] args)
{
Test t = new Test();
System.out.println(t.x);
}
}
1
0
10
11
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Predict the output:
class Base {
protected void foo() {}
}
class Derived extends Base {
void foo() {}
}
public class Main {
public static void main(String args[]) {
Derived d = new Derived();
d.foo();
}
}
Runtime Error
Garbage Value
0
Compile time Error
Similar Resources on Wayground
10 questions
CMP128 Java Ch. 05 Methods

Quiz
•
University
10 questions
Java Inheritance

Quiz
•
University
10 questions
java MCQ

Quiz
•
University
10 questions
exception

Quiz
•
University
10 questions
Java Arrays

Quiz
•
University
10 questions
Java Basic 1

Quiz
•
University
10 questions
Java Quiz 1

Quiz
•
University
10 questions
Briefing Operator Java

Quiz
•
University
Popular Resources on Wayground
50 questions
Trivia 7/25

Quiz
•
12th Grade
11 questions
Standard Response Protocol

Quiz
•
6th - 8th Grade
11 questions
Negative Exponents

Quiz
•
7th - 8th Grade
12 questions
Exponent Expressions

Quiz
•
6th Grade
4 questions
Exit Ticket 7/29

Quiz
•
8th Grade
20 questions
Subject-Verb Agreement

Quiz
•
9th Grade
20 questions
One Step Equations All Operations

Quiz
•
6th - 7th Grade
18 questions
"A Quilt of a Country"

Quiz
•
9th Grade