Quiz on methods

Quiz
•
Computers
•
University
•
Hard
Jeevitha P
Used 11+ times
FREE Resource
6 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
What will be the output of the following program?
public class Madam
{
public static void main(String[] args)
{
int a = 5;
System.out.println(cube(a));
}
static int cube(int theNum)
{
return theNum * theNum * theNum;
}
}
Throws an ArithmeticException.
125
Compilation Error or Runtime Error for some other reason.
Compilation Error because cube is already defined in the java.lang.Math class.
2.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
What will be the output of the following program?
class Equation1
{
public static void main(String s[])
{
int x = 6;
int y = 3;
int z = 12;
int w = method1(x, y, z);
System.out.println("w = " + w);
}
public static int method1(int y, int z, int x)
{
return (x * z) / y;
}
}
w = 24
Compilation Error
w = 36
w = 6
3.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
What will be the output of the following program.
class MethodsTest
{
public static void main(String s[])
{
int a = 34;
int b = 56;
int c = 0;
sum(a, b);
System.out.println("c = " + c);
}
public static int sum(int a, int b)
{
System.out.println("a = " + a + " b = " + b);
int c = 0;
c = a + b;
System.out.println("c = " + c);
return c;
}
}
a = 34 b = 56
c = 90
c = 90
a = 34 b = 56
c = 90
c = 0
a = 34 b = 56
c = 0
c = 0
Compilation Error
4.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
What is the output of the following program?
public class Test
{ public int getData()
{
return 0;
}
public long getData()
{
return 1;
}
public static void main(String[] args)
{
Test obj = new Test(); System.out.println(obj.getData());
} }
1
0
Runtime error
Compilation error
5.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
What is the output of the following program?
public class Test
{
private String function()
{
return ("GFG");
}
public final static String function(int data)
{
return ("GeeksforGeeks");
}
public static void main(String[] args)
{
Test obj = new Test();
System.out.println(obj.function());
}
}
Compilation error
Runtime error
GFG
None of these
6.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
What is the output of the following program?
public class Test
{
private String function(float i, int f)
{
return ("gfg");
}
private String function(double i, double f)
{
return ("GFG");
}
public static void main(String[] args)
{
Test obj = new Test();
System.out.println(obj.function(1., 20));
}
}
GFG
Compilation error
Runtime error
GeeksforGeeks
Similar Resources on Wayground
10 questions
Exception Handling and CollectionQuiz

Quiz
•
University
10 questions
Exercise 1 OOP

Quiz
•
University
10 questions
Basics of C

Quiz
•
University
5 questions
Tema 5: Modularidad

Quiz
•
University
6 questions
Sains Komputer Tingkatan 4 (1.5 Amalan Terbaik Pengaturcaraan)

Quiz
•
7th Grade - Professio...
10 questions
APP Quiz 1

Quiz
•
University
10 questions
Java Arrays

Quiz
•
University
10 questions
Quiz de Java

Quiz
•
University
Popular Resources on Wayground
10 questions
Video Games

Quiz
•
6th - 12th Grade
20 questions
Brand Labels

Quiz
•
5th - 12th Grade
15 questions
Core 4 of Customer Service - Student Edition

Quiz
•
6th - 8th Grade
15 questions
What is Bullying?- Bullying Lesson Series 6-12

Lesson
•
11th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
22 questions
Adding Integers

Quiz
•
6th Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
Discover more resources for Computers
20 questions
Definite and Indefinite Articles in Spanish (Avancemos)

Quiz
•
8th Grade - University
7 questions
Force and Motion

Interactive video
•
4th Grade - University
36 questions
Unit 5 Key Terms

Quiz
•
11th Grade - University
7 questions
Figurative Language: Idioms, Similes, and Metaphors

Interactive video
•
4th Grade - University
15 questions
Properties of Equality

Quiz
•
8th Grade - University
38 questions
WH - Unit 3 Exam Review*

Quiz
•
10th Grade - University
21 questions
Advise vs. Advice

Quiz
•
6th Grade - University
12 questions
Reading a ruler!

Quiz
•
9th Grade - University