Home > Java Programming > Quizzes > Java Basics Practice Test: Classes and Methods
Java Basics Practice Test: Classes and Methods
Fast practice, instant feedback. Timer auto-submits when time’s up.
Avg score: 0% Most missed: “What is the process of defining more than one method in a class differentiated b…”
Java Quiz on fundamentals of classes, methods basics, heap and garbage collection, object creation, constructors, access control, string class, method overloading and static keyword, command line arguments and recursion. Java Classes Static Class: A static class is a class that contains only static methods and variables. Static classes cannot be instantiated, and they are often used to create utility classes. Final Class: A final class is a class that cannot be extended. Final classes are often used to create classes that represent immutable data, such as the String class. Abstract Class:... Show more
Java Basics Practice Test: Classes and Methods
Time left 00:00
25 Questions

1. In the following Java code, which call to sum() method is appropriate?
class Output
{
 
public static int sum(int ...x)
{
return;
}
static void main(String args[])
{
sum(10);
sum(10,20);
sum(10,20,30);
sum(10,20,30,40);
}
}
2. What will be the output of the following Java program?
class box
{
int width;
int height;
int length;
int volume;
void volume(int height, int length, int width)
{
volume = width * height * length;
}
}
class Prameterized_method{
public static void main(String args[])
{
box obj = new box();
obj.height = 1;
obj.length = 5;
obj.width = 5;
obj.volume(3, 2, 1);
System.out.println(obj.volume);
}
}
3. Which of these operators is used to allocate memory for an object?
4. What is the process by which we can control what parts of a program can access the members of a class?
5. What is true of final class?
6. Which method can be defined only once in a program?
7. Which of these keywords is used to refer to member of base class from a subclass?
8. How many arguments can be passed to main()?
9. What will be the output of the following Java snippet, if attempted to compile and run this code with command line argument “java abc Rakesh Sharma”?
public class abc
{
int a=2000;
public static void main(String argv[])
{
System.out.println(argv[1]+" :-Please pay Rs."+a);
}
}
10. Which class allows parsing of command line arguments?
11. Which of the following has the highest memory requirement?
12. How many copies of static and class variables are created when 10 objects are created of a class?
13. What will be the output of the following Java program?
class string_class
{
public static void main(String args[])
{
String obj = "I LIKE JAVA";
System.out.println(obj.length());
}
}
14. All the variables of class should be ideally declared as?
15. What will be the output of the following Java program?
class access
{
public int x;
static int y;
void cal(int a, int b)
{
x += a ;
y += b;
}
}
class static_specifier
{
public static void main(String args[])
{
access obj1 = new access();
access obj2 = new access();
obj1.x = 0;
obj1.y = 0;
obj1.cal(1, 2);
obj2.x = 0;
obj2.cal(2, 3);
System.out.println(obj1.x + " " + obj2.y);
}
}
16. Which of these is the method which is executed first before execution of any other thing takes place in a program?
17. Which function is used to perform some action when the object is to be destroyed?
18. Which one of the following is not an access modifier?
19. What is true about private constructor?
20. Which keyword is used by the method to refer to the object that invoked it?
21. Which of these data types is used by operating system to manage the Recursion in Java?
22. Which of the following statements are incorrect?
23. What is true about Class.getInstance()?
24. What will be the output of the following Java snippet, if attempted to compile and execute?
class abc
{
public static void main(String args[])
{
if(args.length>0)
System.out.println(args.length);
}
}
25. Which of these statement is incorrect?