Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Santanub
S
Santanub
Community Contributor
Quizzes Created: 1 | Total Attempts: 79
| Attempts: 79 | Questions: 79
Please wait...
Question 1 / 79
0 %
0/100
Score 0/100
1. Class Student {    private Student() {    }    static void show(int... id) {    }    static void show(String... id) {    }    static void show(double... id) {    }    public static void main(String args[]) {        //statement    }} Write only one complete statement to call show method that shows ambiguity problem

Explanation

The statement "Student.show();" causes an ambiguity problem because there are multiple overloaded methods with the same name "show" that can be called. The methods have different parameter types (int, String, double), but since no arguments are provided in the statement, the compiler cannot determine which method to invoke.

Submit
Please wait...
About This Quiz
Aptitude Test (C & Java) - Quiz

This Aptitude Test (C & Java) assesses knowledge in Java programming, focusing on concepts like method overloading, interface inheritance, and static methods. It tests understanding through code execution and theoretical questions, essential for students and professionals in software development.

Personalize your quiz and earn a certificate with your name on it!
2. Int a;a=scanf("%d",&a);​printf("%d",a);(user gives 5 as input) what will the output? 

Explanation

The output will be 1. The code first reads an integer input from the user using the scanf function and stores it in the variable 'a'. The scanf function returns the number of successful conversions, in this case, it will return 1. Then, the printf function is used to print the value of 'a', which is 1.

Submit
3. Int j,k,c=0;for(j=1;j<4;j++)for(k=0;k<4;k++)  c++;printf("%d",c); output?

Explanation

The given code snippet initializes three variables: j, k, and c. It then enters a nested loop, with the outer loop iterating from 1 to 3, and the inner loop iterating from 0 to 3. In each iteration of the inner loop, the value of c is incremented by 1. Since there are 3 iterations of the outer loop and 4 iterations of the inner loop, the value of c is incremented a total of 3 * 4 = 12 times. Finally, the value of c is printed, which is 12.

Submit
4. Int a;a=scanf("%d",&a);​printf("%d",a);(user gives 5 as input) what will the output? 

Explanation

The output will be 1. The code first reads an integer input from the user using the scanf function and stores it in the variable 'a'. The scanf function returns the number of successfully scanned items, which in this case is 1. Then, the printf function is used to print the value of 'a', which is 1.

Submit
5. Class Student {    private Student() {    }    static void show(int... id) {    }    static void show(String... id) {    }    static void show(double... id) {    }    public static void main(String args[]) {        //statement    }} Write only one complete statement to call show method that shows ambiguity problem

Explanation

The given code defines three static methods with variable arguments of different types (int, String, double). When calling the show method without any arguments, it will result in an ambiguity problem because the compiler cannot determine which method should be invoked. Therefore, the statement "Student.show();, show();" will cause an ambiguity error.

Submit
6. Write the output ...public class Cal {     int s;     int add(int... d) {        for (int i : d) {            s += i;        }        return s;    }     public static void main(String args[]) {        int[] i = {1, 3-2, 5, 7, 1-9};        System.out.println(new Cal().add(i));    }}

Explanation

The given code defines a class called "Cal" with an instance variable "s" and a method called "add" that takes in a variable number of integers as arguments. The method iterates over the given integers and adds them to the instance variable "s". Finally, the method returns the value of "s".

In the main method, an array of integers "i" is created with the values {1, 3-2, 5, 7, 1-9}. The add method is called on a new instance of the "Cal" class, passing in the array "i" as an argument. The add method adds all the integers in the array to the instance variable "s" and returns the value of "s", which is 6.

Therefore, the output of the code is 6.

Submit
7. Write the output ... public class Cal {     int[] a;    int s;     Cal(int... v) {        a = v;    }     int add(Cal... d) {        for (Cal c : d) {            for (int i : c.a) {                s += i;            }        }        return s;    }     public static void main(String args[]) {        int[] ar = {9, 7, 5, 3};        Cal cal = new Cal(ar);        System.out.println(new Cal().add(cal));    }}

Explanation

The code defines a class called "Cal" with an instance variable "a" of type int array and another instance variable "s" of type int. It also defines a constructor that takes in a variable number of integers and assigns them to the "a" array.

The "add" method takes in a variable number of "Cal" objects and iterates over each object. For each object, it iterates over the "a" array and adds each element to the "s" variable. Finally, it returns the value of "s".

In the main method, an integer array "ar" is created with values [9, 7, 5, 3]. A new "Cal" object "cal" is created with "ar" as the argument for the constructor. The "add" method is called on a new instance of "Cal" without any arguments, passing in "cal" as the argument. The result, which is 24, is printed to the console.

Submit
8. Write the output ... public class Cal {     int[] a;    static int s;     Cal(int... v) {        a = v;    }     int add(Cal... d) {        for (Cal c : d) {            for (int i : c.a) {                s += i;            }        }        return s;    }     public static void main(String args[]) {        int[] ar = {1, 9, 4, 7};        int[] ar2={};                Cal cal = new Cal(ar);        Cal cal2 = new Cal(ar2);                System.out.print(new Cal().add(cal));        System.out.print(new Cal().add(cal2));    }}

Explanation

The output of the code is 2121. This is because the code creates two instances of the Cal class, cal and cal2, with different arrays as arguments. The add() method in the Cal class takes a variable number of Cal objects as arguments. Inside the add() method, it iterates over each Cal object and then iterates over each element in the array of that object. It adds each element to the static variable s. Since s is a static variable, its value is shared among all instances of the Cal class. Therefore, when add() is called on cal and cal2, the elements of both arrays are added to s. Finally, the value of s is returned, which is 2121.

Submit
9. Write the output ... public class Cal {     int[] a;    static int s;     Cal(int... v) {        a = v;    }     int add(Cal... d) {        for (Cal c : d) {            for (int i : c.a) {                s += i;            }        }        return s;    }     public static void main(String args[]) {        int[] ar = {1, 9, 1, 3};        int[] ar2={};                Cal cal = new Cal(ar);        Cal cal2 = new Cal(ar2);                System.out.print(new Cal().add(cal));        System.out.print(new Cal().add(cal2));    }     static {         s = - 2;    }}

Explanation

The given code defines a class Cal with an instance variable a (an integer array) and a static variable s (an integer). The class also has a constructor that takes in variable arguments and assigns them to the instance variable a. There is also a method add that takes in variable arguments of type Cal and adds up all the integers in the arrays of those Cal objects and stores the sum in the static variable s. The main method creates two instances of Cal, one with an array [1, 9, 1, 3] and the other with an empty array. It then calls the add method on both instances and prints the value of s. Since s is a static variable, the value is shared between all instances of Cal. The initial value of s is -2, and when add is called on the first instance, it adds up all the integers in the array [1, 9, 1, 3] and stores the sum in s. When add is called on the second instance with an empty array, it does not add anything to s. Therefore, the final value of s is the sum of the integers in the first array, which is 12. Hence, the output is 1212.

Submit
10. Class StaticTest {    static {        System.out.print("A");    }    static {        System.out.print("D");    }    public static void main(String args[]) {    }    static {        System.out.print("Z");    }    static {        System.out.print("E");    }}

Explanation

The code provided is a class named StaticTest. Inside the class, there are four static blocks, which are executed in the order they appear in the code. Each static block is responsible for printing a specific letter: "A", "D", "Z", and "E". Therefore, when the main method is called, the output will be "ADZE", which matches the given answer.

Submit
11. Find the output ...class StaticTest {    static {        System.out.print("A");    }    static {        System.out.print("E");    }    public static void main(String args[]) {    }    static {        System.out.print("Z");    }    static {        System.out.print("D");    }}

Explanation

The given code defines a class called StaticTest. It contains four static blocks, which are executed in the order they appear in the code.

The first static block prints "A", the second static block prints "E", the third static block prints "Z", and the fourth static block prints "D".

In the main method, there is no code to execute, so it does nothing.

Therefore, the output of the code will be "AEZD".

Submit
12. Class Game {     String title;    int ver;     public Game() {    }     public Game(String title, int ver) {        this.title = title;        this.ver = ver;    }     Game[] getGame() {        Game fifa = new Game("-FIFA", 1);        Game nfs = new Game("-NFS", 2);        Game igi = new Game("IGI", 1);        Game igi2 = new Game("-IGI2", 2);         Game[] game = {igi, igi2, nfs, fifa};         return game;    }} class Computer {     public static void main(String args[]) {        for (Game game : new Game().getGame()) {            System.out.print(game.title + ":" + game.ver);        }    }}

Explanation

The code provided defines two classes, "Game" and "Computer". The "Game" class has two constructors, one with no parameters and one with a "title" and "ver" parameter. The "Game" class also has a method called "getGame" which creates four instances of the "Game" class and stores them in an array. The "Computer" class has a main method which iterates over the array returned by the "getGame" method and prints the "title" and "ver" values of each "Game" object. The output "IGI:1-IGI2:2-NFS:2-FIFA:1" indicates that the "title" and "ver" values of each "Game" object are being printed in the correct order.

Submit
13. Write only outputclass Department {     int code;    String name;     Department() {    }     Department(int c, String n) {        code = c;        name = n;    }     Department[] getAll() {        Department cse = new Department(100, "ME");        Department ce = new Department(101, "EE");        Department me = new Department(102, "ECE");        Department ece = new Department(103, "CE");        Department ee = new Department(104, "CSE");         Department[] dept = {cse, ece, ee, ce, me};         return dept;    }} class College {     public static void main(String... args) {        for (Department d : new Department().getAll()) {            System.out.print(d.name.charAt(1));        }    }}

Explanation

The code provided defines a class Department with two constructors and a method getAll(). The getAll() method creates five Department objects with different codes and names and stores them in an array. In the main method of the College class, a for loop is used to iterate over the array returned by the getAll() method. For each Department object, the second character of the name is printed. In this case, the output is "EESEC" because the second character of each department name (ME, EE, ECE, CE, CSE) is "E".

Submit
14. Class Department {     static void showName() {        System.out.print("1");    }     static {        System.out.print("2");    }} class College {     static {        System.out.print("3");    }     public static void main(String... args) {        Department.showName();    }    static {        System.out.print("4");    }}

Explanation

The code snippet provided consists of two classes, Department and College. The Department class has a static method called showName() which prints "1". The College class has a main method which calls the showName() method from the Department class.

The static blocks in the code are executed when the class is loaded. The static block in the Department class prints "2" and the static block in the College class prints "3".

Therefore, when the main method is executed, the output will be "3" followed by "4" from the static blocks in the College class, and then "2" and "1" from the showName() method in the Department class.

Hence, the correct answer is 3421.

Submit
15. Write only output ...class Department {     static void showName() {        System.out.print("C");    }     static {        showName();        System.out.print("S");    }} class College {     static {        System.out.print("E");    }     public static void main(String... args) {    }}

Explanation

The correct answer is "E" because the static block in the College class is executed first before any other code in the class. In the static block, "E" is printed to the console. Since there is no other code in the main method or any other static block, "E" is the only output.

Submit
16. Write only output ...class Department {     static {        System.out.print("2");    }    static void showName() {        System.out.print("#");    }     static {        System.out.print("#");    }} class College {     static {        System.out.print("M");    }     public static void main(String... args) {    }    static {        System.out.print("I");        Department.showName();    }}

Explanation

The given code consists of two classes, Department and College. The static blocks in the Department class are executed first, printing "2#" on the console. Then, the static blocks in the College class are executed, printing "M" and "I" on the console. Finally, the main method in the College class is called, but it is empty, so no additional output is generated. Therefore, the output of the code is "MI2##".

Submit
17. Write only output ... class Department{    void showDept(){        System.out.print("All");    }}class CSE extends Department{    void showDept(){        System.out.print("CSE");    }}class EEE extends Department{    void showDept(){        System.out.print("EEE");    }}class EI extends Department{    void showDept(){        System.out.print("EI");    }}class College{    public static void main(String args[]) {        Department d1=new CSE();        Department d2=new EEE();        Department d3=new EI();         d1.showDept();        d2.showDept();        d3.showDept();    }}

Explanation

The code creates objects of different classes that extend the Department class. Each subclass has its own implementation of the showDept() method. The objects are then assigned to variables of the Department type. When the showDept() method is called on each object, the method of the corresponding subclass is executed. Therefore, the output is "CSEEEEEI", as the showDept() method of the CSE class is called first, followed by the showDept() methods of the EEE and EI classes.

Submit
18. Class Department{    String name="S";    void showDept(Department d){        System.out.print(d.name);    }}class CSE extends Department{    CSE(String n) {        name=n;    }}class EEE extends Department{    EEE(String n) {        name=n;    }}class EI extends Department{    EI(String n) {        name=n;    }}class College{    public static void main(String args[]) {        Department d=new Department();        d.showDept(new CSE("S"));        d.showDept(new EEE("E"));        d.showDept(new EI("I"));    }}

Explanation

The given code defines a class hierarchy with a base class "Department" and three derived classes "CSE", "EEE", and "EI". Each derived class has a constructor that takes a string parameter and assigns it to the "name" variable inherited from the base class. The "showDept" method in the base class prints the value of the "name" variable. In the main method, three objects of the derived classes are created and passed to the "showDept" method of the base class. The "name" values passed are "S" for CSE, "E" for EEE, and "I" for EI. Therefore, the output of the program is "SEI".

Submit
19. Write the output ...public class Cal {     int s;     int add(int... d) {        for (int i : d) {            s += i;        }        return s;    }     public static void main(String args[]) {        int[] i = {1, 3-2, 5, 7, 2-9};        System.out.println(new Cal().add(i));    }}

Explanation

The output of the code is 5 because the add() method takes in a variable number of integers as arguments and adds them together. In the main() method, an array of integers is created with the values {1, 3-2, 5, 7, 2-9}. The expression 3-2 and 2-9 are evaluated to 1 and -7 respectively. Hence, the array becomes {1, 1, 5, 7, -7}. When this array is passed to the add() method, it iterates over each element and adds them together. The sum of the elements is 5, which is then returned and printed as the output.

Submit
20. Write the output ... public class Cal {     int[] a;    int s;     Cal(int... v) {        a = v;    }     int add(Cal... d) {        for (Cal c : d) {            for (int i : c.a) {                s += i;            }        }        return s;    }     public static void main(String args[]) {        int[] ar = {9, 7, -5, 3};        Cal cal = new Cal(ar);        System.out.println(new Cal().add(cal));    }}

Explanation

The code defines a class called "Cal" with an instance variable "a" of type int array and another instance variable "s" of type int. The class also has a constructor that takes variable arguments of type int and assigns them to the "a" variable. There is also a method called "add" that takes variable arguments of type "Cal" and returns the sum of all the integers in the "a" arrays of the "Cal" objects passed as arguments.

In the main method, an integer array "ar" is created and initialized with values. Then, a new instance of "Cal" is created using the array "ar" as an argument. Finally, the "add" method is called on a new instance of "Cal" with the previously created instance as an argument. The sum of all the integers in the "a" array of the "Cal" instance is printed, which is 14.

Submit
21. Write the output ... public class Cal {     int[] a;    static int s;     Cal(int... v) {        a = v;    }     int add(Cal... d) {        for (Cal c : d) {            for (int i : c.a) {                s += i;            }        }        return s;    }     public static void main(String args[]) {        int[] ar = {1, 9, 3, 7};        int[] ar2={};                Cal cal = new Cal(ar);        Cal cal2 = new Cal(ar2);                System.out.print(new Cal().add(cal));        System.out.print(new Cal().add(cal2));    }}

Explanation

The output of the code is 2020.


- The `Cal` class has a constructor that takes in a variable number of integers and assigns them to the `a` array.
- The `add` method takes in a variable number of `Cal` objects and iterates over each `Cal` object.
- For each `Cal` object, it iterates over the `a` array and adds each element to the static variable `s`.
- In the `main` method, two `Cal` objects are created, one with the array {1, 9, 3, 7} and the other with an empty array.
- The `add` method is called on both `Cal` objects and the result is printed.
- Since the static variable `s` is not reset between the two method calls, the sum of the elements in the first `Cal` object's `a` array (20) is added to the sum of the elements in the second `Cal` object's `a` array (0), resulting in an output of 2020.

Submit
22. Write the output ... public class Cal {     int[] a;    static int s;     Cal(int... v) {        a = v;    }     int add(Cal... d) {        for (Cal c : d) {            for (int i : c.a) {                s += i;            }        }        return s;    }     public static void main(String args[]) {        int[] ar = {1, 9, 1, 3};        int[] ar2={};                Cal cal = new Cal(ar);        Cal cal2 = new Cal(ar2);                System.out.print(new Cal().add(cal));        System.out.print(new Cal().add(cal2));    }     static {         s = - 3;    }}

Explanation

The code defines a class Cal with an instance variable a and a static variable s. The constructor of Cal takes in a variable number of arguments and assigns them to the instance variable a. The add method takes in a variable number of Cal objects and sums up all the integers in their respective a arrays. In the main method, two instances of Cal are created, one with an array [1, 9, 1, 3] and another with an empty array. The add method is called on both instances and the result is printed. Since the add method sums up all the integers in the array, the sum of [1, 9, 1, 3] is 14 and the sum of an empty array is 0. Therefore, the output is 1111.

Submit
23. Class StaticTest {    static {        System.out.print("A");    }    static {        System.out.print("D");    }    public static void main(String args[]) {    }    static {        System.out.print("E");    }    static {        System.out.print("Z");    }}

Explanation

The given code is a class named StaticTest. It contains four static blocks, which are executed in the order they appear in the code.

The first static block prints "A".

The second static block prints "D".

The third static block prints "E".

The fourth static block prints "Z".

Therefore, when the code is executed, it will print "ADEZ" as the output.

Submit
24. Find the output ...class StaticTest {    static {        System.out.print("A");    }    static {        System.out.print("E");    }    public static void main(String args[]) {    }    static {        System.out.print("Z");    }    static {        System.out.print("D");    }}

Explanation

The given code is a class named "StaticTest" with a main method. The class has multiple static blocks, which are executed in the order they appear in the code.

The first static block prints "A", the second static block prints "E", the third static block prints "Z", and the fourth static block prints "D".

Therefore, the output of the code will be "AEZD".

Submit
25. Write only outputclass Department {     int code;    String name;     Department() {    }     Department(int c, String n) {        code = c;        name = n;    }     Department[] getAll() {        Department cse = new Department(100, "ME");        Department ce = new Department(101, "EE");        Department me = new Department(102, "ECE");        Department ece = new Department(103, "CE");        Department ee = new Department(104, "CSE");         Department[] dept = {cse, ece, ee, ce, me};         return dept;    }} class College {     public static void main(String... args) {        for (Department d : new Department().getAll()) {            System.out.print(d.name.charAt(1));        }    }}

Explanation

The code provided defines a class called Department with two constructors and a method called getAll(). In the getAll() method, five Department objects are created and stored in an array called dept. The main method in the College class then calls the getAll() method and iterates over the array of Department objects. For each Department object, it prints the character at index 1 of the name string. In this case, the names of the Department objects are "ME", "EE", "ECE", "CE", and "CSE". The character at index 1 of each name is "E", "E", "C", "E", and "S" respectively. Therefore, the output will be "EESEC".

Submit
26. Write only output ...class Department {     static void showName() {        System.out.print("C");    }     static {        showName();        System.out.print("S");    }} class College {     static {        System.out.print("E");    }     public static void main(String... args) {    }}

Explanation

The correct answer is "E" because the static block in the College class is executed first before any other code in the class. In the static block, the statement System.out.print("E") is executed, which prints "E" as the output.

Submit
27. Write only output ...class Department {     static {        System.out.print("2");    }    static void showName() {        System.out.print("#");    }     static {        System.out.print("#");    }} class College {     static {        System.out.print("M");    }     public static void main(String... args) {    }    static {        System.out.print("I");        Department.showName();    }}

Explanation

The output "MI2##" is obtained by following the sequence of statements in the code.
First, the static block in the Department class is executed, printing "2".
Then, the static block in the College class is executed, printing "M".
Next, the static block in the Department class is executed again, printing "#".
Finally, the main method is called in the College class, but it is empty and does not have any statements to execute.
Therefore, the output is "MI2##".

Submit
28. Write only output ... class Department{    void showDept(){        System.out.print("All");    }}class CSE extends Department{    void showDept(){        System.out.print("CSE");    }}class EEE extends Department{    void showDept(){        System.out.print("EEE");    }}class EI extends Department{    void showDept(){        System.out.print("EI");    }}class College{    public static void main(String args[]) {        Department d1=new CSE();        Department d2=new EEE();        Department d3=new EI();         d1.showDept();        d2.showDept();        d3.showDept();    }}

Explanation

The given code defines a class hierarchy with a base class Department and three derived classes CSE, EEE, and EI. Each class has a method showDept() that prints a specific department name. In the main method, objects of the derived classes are created and assigned to Department type variables. When the showDept() method is called on these objects, the overridden version of the method in each derived class is executed, printing the respective department name. Therefore, the output of the code is "CSEEEEEI".

Submit
29. Int a=500,b=300;if(!(a>b))    printf("True");else    printf("False");output?

Explanation

The given code compares the values of variables 'a' and 'b'. The condition inside the 'if' statement is "!(a>b)", which means "not (a is greater than b)". Since a is indeed greater than b (500 is greater than 300), the condition evaluates to false. Therefore, the code will execute the 'else' block and print "False" as the output.

Submit
30. What is the output of this C code?     #include <stdio.h>    void main()    {        double k = 0;        for (k = 0.0; k < 3.0; k++)            printf("Hello");    }

Explanation

The code will print "Hello" three times. The for loop initializes the variable k to 0.0 and continues to execute as long as k is less than 3.0. In each iteration of the loop, "Hello" is printed. Since the loop increments k by 1 each time, the loop will execute three times (when k is 0.0, 1.0, and 2.0), resulting in "Hello" being printed thrice.

Submit
31. Int a=500,b=300;if(!(a>b))    printf("True");else    printf("False");output?

Explanation

The code first checks if the condition !(a>b) is true. In this case, a is not greater than b, so the condition is true. Therefore, the code will execute the statement printf("True"). However, since there is an else statement after the if condition, the code will also execute the statement printf("False"). So, the output will be TrueFalse.

Submit
32. Int a=4,b=2;if(a%2==0)   printf("hello");   printf("bye");

Explanation

The code snippet first checks if the value of 'a' is divisible by 2 using the modulus operator (%). Since 4 is divisible by 2, the condition is true and the first printf statement "hello" is executed. Then, the second printf statement "bye" is also executed. Therefore, the output will be "hello" followed by "bye", which matches the given answer "hellobye".

Submit
33. What is the value of x in this C code?    #include     void main()    {        int x = 5 * 9 / 3 + 9;    }

Explanation

The value of x in this C code is 24. This is because the expression "5 * 9 / 3 + 9" is evaluated according to the order of operations (PEMDAS/BODMAS). First, the multiplication 5 * 9 is performed, resulting in 45. Then, the division 45 / 3 is performed, resulting in 15. Finally, the addition 15 + 9 is performed, resulting in 24. Therefore, the value of x is 24.

Submit
34. If an exception is generated and there is no matching catch block, default exception handler handles that exception

Explanation

If an exception is generated and there is no matching catch block, the default exception handler handles that exception. This means that if an exception is thrown and there is no specific catch block to handle it, the default exception handler will take over and handle the exception. This default handler may display an error message or perform some other default action to handle the exception. Therefore, the statement "True" is correct.

Submit
35. Int a=3,b=4,c=1;printf("%d%d%d",a+b,scanf("%d%d%d",&a,&b,&c),a+b);inputs are as follow - a=10 b=12 c=13.Hence the ouput is?

Explanation

The output is "22 3 7" because the printf function is called with the format string "%d%d%d". The first %d is replaced by the sum of a and b (3+4=7), the second %d is replaced by the return value of the scanf function, which is the number of successful conversions made (3 in this case), and the third %d is replaced by the sum of a and b again (10+12=22). Therefore, the final output is "22 3 7".

Submit
36. Int a=700;if(!a>400)    printf("Jaipur");else     printf("Kolkata");output

Explanation

The correct answer is "Kolkata" because the condition in the if statement is false. The condition is "!a>400" which means "not a greater than 400". Since a is equal to 700, the condition evaluates to false and the code inside the else block is executed, which prints "Kolkata".

Submit
37. Find output class System2 {    int opp(int a, int b) {        try {            System.out.print("1");            return a/b;        }catch(Exception ex) {            System.out.print("1");                    return -1;    }finally {            System.out.print("0");        }    }    public static void main(String args[]) {        System.out.print(new System2().opp(2,0));    }}

Explanation

The output is "110-1" because the method opp(2,0) is called in the main method. Inside the opp() method, a try-catch-finally block is used. In the try block, the statement "System.out.print("1");" is executed, and then a division operation "return a/b;" is performed. Since the division by zero is not allowed, an exception is thrown. The catch block catches the exception, prints "1", and returns -1. Finally, the finally block is executed and "0" is printed. Therefore, the output is "110-1".

Submit
38. Int main(){int i = 10,*p;p= &i;printf("%u\n", p);}

Explanation

The correct answer is "address of i". In the given code, the variable "i" is assigned a value of 10. The pointer variable "p" is then assigned the address of "i" using the "&" operator. The printf statement prints the value of "p", which is the address of "i". Therefore, the output will be the address of "i".

Submit
39. Int a=1;printf("%d%d%d",a,a++,++a);output?

Explanation

The output is 3 2 2. This is because the printf function is called with the format string "%d%d%d". The first %d is replaced with the value of a, which is 1. Then, the second %d is replaced with the value of a++, which is 1, but the value of a is incremented to 2 after the expression is evaluated. Finally, the third %d is replaced with the value of ++a, which is 2 since the value of a is incremented before the expression is evaluated. Therefore, the output is 3 2 2.

Submit
40. Int i,c=0;for(i=1;i<12;i++)c++;printf("%​d",c); output?

Explanation

The given code initializes a variable 'c' to 0 and then enters a for loop that iterates from 1 to 11. In each iteration, the value of 'c' is incremented by 1. Therefore, the loop executes 11 times and at the end, the value of 'c' becomes 11. Finally, the printf statement prints the value of 'c' which is 11.

Submit
41. Find the output ...class Game {    public static void main(String... args) {        for (String s : args) {            System.out.print(s);        }     }     static {        String[] args = {"Call of duty", " MW3"};        main(args);    }}

Explanation

The correct answer is "Call of duty MW3". This is because the main method is called from the static block, passing an array of strings as an argument. The for loop in the main method then iterates over each string in the array and prints it. Therefore, the output will be "Call of duty MW3".

Submit
42. Public class Test {    int dis(int b){        try{            return 10/b;        }catch(Exception ex){            return 1;        }finally{            return 2;        }    }    public static void main(String[] args) {        System.out.println(new Test().dis(0));    }}

Explanation

The code will throw an exception when trying to divide 10 by 0 in the try block. Since there is a catch block that catches any exception, the catch block will execute and return 1. However, the finally block will always execute regardless of whether an exception is thrown or caught. In this case, the finally block will execute and return 2. Therefore, the final output will be 2.

Submit
43. Int add(int x,int y){int z=(x+ ++y);return z ;}void main(){ int i=50,b;b= add(i,5) ;printf("%d",b);}

Explanation

The given code defines a function `add` that takes two integers `x` and `y`, increments `y` by 1 and adds `x` and the incremented value of `y` to get `z`. The function then returns the value of `z`. In the `main` function, an integer `i` is assigned the value 50, and another integer `b` is declared. The `add` function is called with `i` and 5 as arguments, and the returned value is assigned to `b`. Finally, the value of `b` is printed, which is 56.

Submit
44. Int i,c=0;for(i=1;i<12;i++)c++;printf("%​d",c); output?

Explanation

The given code initializes the variable 'c' to 0 and then enters a loop that runs 11 times (from i=1 to i

Submit
45. The output of the code below is     #include <stdio.h>    void main()    {        int x = 5;        if (x < 1)            printf("hello");        if (x == 5)            printf("hi");        else            printf("no");    }

Explanation

The output of the code is "hi" because the value of x is 5. The first if statement is not true because x is not less than 1, so "hello" is not printed. The second if statement is true because x is equal to 5, so "hi" is printed. The else statement is not executed because the second if statement is true. Therefore, the output is "hi".

Submit
46. Int main(){int i = 10,*p = &i;printf("%d\n", *p);}

Explanation

The code declares an integer variable i and a pointer variable p, which is assigned the address of i. The printf statement then dereferences the pointer p and prints the value stored at that memory location, which is 10. Therefore, the correct answer is 10.

Submit
47. Int main(){int i = 10,*p;p= &i;printf("%d\n", *(&p));}

Explanation

The given code declares an integer variable i and a pointer variable p. The pointer p is assigned the address of i using the address-of operator (&). The printf statement is used to print the value pointed to by the pointer p, which is the value stored in the variable i. Therefore, the correct answer is "address of i", as it will print the memory address where the variable i is stored.

Submit
48. Int i,n;scanf("%d",&n);for(i=1;i<=n;i++)   if(!(n%i))        printf("%d\n",i);The following program will_______

Explanation

The given program takes an input number 'n' and then iterates through all numbers from 1 to 'n'. For each iteration, it checks if 'n' is divisible by the current number 'i' using the condition "!(n%i)". If 'n' is divisible by 'i', then 'i' is a factor of 'n'. Therefore, the program will print all the factors of the input number 'n'.

Submit
49. What is the output of this C code?    #include  <stdio.h>    int main()    {       signed char chr;       chr = 128;       printf("%d\n", chr);       return 0;    }

Explanation

The output of this C code is -128. In this code, a signed char variable named "chr" is assigned the value 128. However, the range of a signed char is -128 to 127. When a value greater than 127 is assigned to a signed char, it overflows and wraps around to the minimum value in its range, which is -128. Therefore, when the printf function is called to print the value of "chr", it will output -128.

Submit
50. Which are true for variable length argument (modern approach)

1. works as an array
2. only one parameter can be used as method parameter
3. any number of arguments or one array can be passed and parameter/s type must be same as varargs type
4. can be used as return type
 

Explanation

Variable length arguments, also known as varargs, allow a method to accept a variable number of arguments of the same type. In the modern approach, varargs work as an array, allowing multiple values to be passed as arguments. Only one parameter can be used as a method parameter, and it must have the same type as the varargs type. Therefore, the correct answer is "1 2 3 only."

Submit
51. Int i,sum;for(i=0,sum=0;i<=5;sum+=i++);printf("%d",sum);output

Explanation

The given code snippet is a for loop that iterates from 0 to 5. Inside the loop, the value of 'i' is added to the 'sum' variable and then incremented. This process continues until 'i' becomes greater than 5. Finally, the value of 'sum' is printed, which is 15.

Submit
52. What is the output of this C code?     #include <stdio.h>    void main()    {        int k = 0;        for (k)            printf("Hello");    }

Explanation

The given code will result in a compile time error. This is because the condition in the for loop is missing, which is required for the loop to execute. In C, the condition inside the parentheses of the for loop should evaluate to either true or false. Since there is no condition specified in this code, the compiler will throw an error.

Submit
53. Find output class System2 {    int opp(int a, int b) {    try {            System.out.print(a/b);        } catch(Exception ex) {            System.out.print(a+b);    } catch(ArithmeticException ex) {            System.out.print(a-b);    }catch(NumberFormatException ex) {            System.out.print(a*b);    }    }    public static void main(String args[]) {        System.out.print(new System2().opp(2,0));    }}

Explanation

The given code will result in a Compilation Error. This is because the catch blocks are not ordered correctly. In Java, catch blocks should be ordered from most specific to least specific. In this case, the catch block for ArithmeticException should come before the catch block for Exception. However, in the given code, the catch block for Exception comes first, which causes a compilation error.

Submit
54. Int i=0;for(;i<=5;i++);    printf("%d",i);output?

Explanation

The given code snippet initializes the variable 'i' to 0 and then enters a for loop. However, the initialization part is missing in the for loop, so it will not execute any code inside the loop. After the loop, the value of 'i' will be 6 due to the post-increment operator 'i++'. Therefore, the output will be 6.

Submit
55. What will be the output?#include<stdio.h>void main(){    int i;    for(i=0;i<=5;i++);    printf("%d",i);   } 

Explanation

The code snippet provided is a simple program that uses a for loop to iterate from 0 to 5. However, there is a semicolon (;) immediately after the for loop declaration, which creates an empty statement. This means that the loop does not have any code block associated with it, and the printf statement outside the loop will only be executed once after the loop iteration is completed. Therefore, the output will be "6".

Submit
56. Add(int,int);void main(){ int i=49,b;b= add(i,5) ;printf("%d",);}void add(int x,int y){int z=(x+ ++y);return z ;}

Explanation

The code provided is attempting to call the function "add" and assign the result to the variable "b". However, there are a few issues with the code. Firstly, the function "add" is declared after it is called, which will cause a compilation error. Additionally, the function "add" is declared to return void, but it is actually returning an integer value. This will also cause a compilation error. Therefore, the correct answer is "error".

Submit
57. Int func(int);main(){int i=0;printf("%d",func(i));printf("%d",func(i));}int func(){return (i+1);}

Explanation

The code provided defines a function called "func" that takes an integer argument and returns that argument plus one. In the main function, an integer "i" is initialized to 0. Then, the "func" function is called twice, passing "i" as the argument each time. Finally, the returned value from each function call is printed. Since the value of "i" is 0 in both function calls, the return value will always be 1. Therefore, the output will be 1,1.

Submit
58. What is the output of this C code?     #include <stdio.h>    void main()    {        int y = 3;        float x = 5 % 2 * y / 2;        printf("Value of x is %f", x);    }

Explanation

The output of this C code is "Value of x is 1.000".

In the code, the variable y is assigned a value of 3. Then, the expression "5 % 2 * y / 2" is evaluated. The modulus operator (%) returns the remainder of the division of 5 by 2, which is 1. Then, the multiplication and division operations are performed, resulting in 1.000. Finally, the printf statement prints the value of x as "Value of x is 1.000".

Submit
59. Subclasses catch exception as type of that class and also its Superclasss

Explanation

Subclasses do not catch exceptions as the type of that class and its superclass. In Java, when an exception is thrown, it is caught by the first catch block that can handle it, based on the type of the exception. If a subclass catches an exception, it cannot also catch the same exception as its superclass. The superclass catch block will not be executed in this case. Therefore, the given statement is false.

Submit
60. Int a=65;printf("%c",a);  output?​

Explanation

The code initializes an integer variable 'a' with the value 65. The printf function is used to print the character representation of 'a'. The '%c' format specifier is used to indicate that the argument should be treated as a character. In ASCII, the decimal value 65 corresponds to the uppercase letter 'A'. Therefore, the output of the code will be 'A'.

Submit
61. Find output

class System2 {
    int d;
    void display() {
        try {
            System.out.print("0");            return d/0;        } catch(Exception ex) {            System.out.print("2");                     return -1;
                } finally {
            System.out.print("f");
        }
    }
    public static void main(String args[]) {
        System.out.print(new System2().display());
    }
}

Explanation

The code in the given question will result in an error. The display() method attempts to return the value of d divided by 0, which is not allowed and will throw an ArithmeticException. However, the catch block will catch this exception and print "2" before returning -1. Finally, the "f" will be printed. So the output will be "02f-1".

Submit
62. What will be output of following c code?        #include<stdio.h>void main(){    int x=123;    int i={         printf("c" "+")    };    for(x=0;x<=i;x++){         printf("%d ",x);    }}

Explanation

The code will result in a compile error. The line "int i={ printf("c"+" ) };" is incorrect syntax. The concatenation of two string literals is not allowed in C.

Submit
63. Find output class System {    int opp(int a, int b) {    try {            System.out.print(a/b);        } catch(Exception ex) {            System.out.print(a-b);    }    }    public static void main(String args[]) {        System.out.print(new System().opp(2,0));    }}

Explanation

The code will result in a compilation error because the method opp() does not have a return statement. The method is declared as returning an int, but there is no return statement in the try or catch block. Therefore, the code will not compile.

Submit
64. which are the correct variable name?(There can be more then one correct answer)

Explanation

The correct variable names in the given options are "_a" and "a_1". Variable names in programming languages can start with an underscore (_) or a letter, followed by any combination of letters, numbers, or underscores. However, variable names cannot start with a number or contain any other special characters. Therefore, options like "1a" and "a.1" are not valid variable names.

Submit
65. Exception can be generated explicitly using key word throws

Explanation

The statement is false because exceptions are not generated explicitly using the keyword "throws". The "throws" keyword is used in method signatures to indicate that the method may throw certain types of exceptions, but it does not actually generate the exceptions. Exceptions are typically generated using the "throw" keyword followed by an instance of the desired exception class.

Submit
66. Float a,b=1.0;for(a=0;a<=3;a+=0.5)b++;printf("%d",b);output?

Explanation

The given code initializes two variables, a and b, with values 0 and 1.0 respectively. It then enters a loop that increments the value of a by 0.5 in each iteration until a reaches 3. In each iteration, the value of b is also incremented by 1. After the loop ends, the code prints the value of b, which is 6. Therefore, the output of the code is 6.

Submit
67. Int a=4.0,b=2.0;float c;c=b/a;printf("%f",c);output?

Explanation

The code initializes two variables, a and b, with the values 4.0 and 2.0 respectively. Then, it declares a float variable c. The next line of code assigns the value of b divided by a to c. Since both a and b are integers, the division is integer division, which means the result will be an integer. In this case, 2 divided by 4 is 0.5, but since it is integer division, the decimal part is truncated, resulting in 0. Finally, the code prints the value of c, which is 0.0.

Submit
68. Find the true statement ...1. NullPointerException is checked exception2. ArithmeticException is checked exception3. ClassNotFoundException is unchecked exception

Explanation

The given answer states that all three statements are false. However, this is incorrect. The correct explanation is that statement 3 is true, while statements 1 and 2 are false. NullPointerException and ArithmeticException are both unchecked exceptions, meaning they do not need to be declared in a method's throws clause or caught in a try-catch block. On the other hand, ClassNotFoundException is a checked exception, which means it must be either declared or caught.

Submit
69. Int i,k,n;scanf("%d",&n);for(i=n,k=1;1<=i;i++)        k*=i;printf("%d",k);what will the following program will do?

Explanation

The given program uses a for loop to calculate the factorial of a number. It takes an integer input from the user and stores it in the variable 'n'. Then, it initializes 'i' with 'n' and 'k' with 1. The for loop runs as long as 'i' is greater than or equal to 1, and in each iteration, it multiplies 'k' with 'i' and decrements 'i' by 1. Finally, it prints the value of 'k', which is the factorial of the input number. Therefore, the program will print the factorial of a number given as input by the user.

Submit
70. Which are true1. members in interface are protected implicitly if interface is protected2. members in interface are public implicitly if interface is public3. interface can inherit another interface4. class can inherit any number of interfaces5. if an abstract class implements an interface, we have to override abstract method of the interface 

Explanation

The given correct answer is 2, 3, 4 only. This means that the statements 2, 3, and 4 are true while the statements 1 and 5 are false. Statement 2 states that members in an interface are public implicitly if the interface is public, which is true. Statement 3 states that an interface can inherit another interface, which is also true. Statement 4 states that a class can inherit any number of interfaces, which is true as well. However, statement 1, which states that members in an interface are protected implicitly if the interface is protected, is false. Statement 5, which states that if an abstract class implements an interface, we have to override the abstract method of the interface, is also false.

Submit
71. Int a=0,b=0;if(!b==a)   printf("Hello")else   printf("Bye"); output?

Explanation

The output of this code will be "Hello". This is because the condition in the if statement is "!b==a", which evaluates to true. In C, the "!" operator is the logical NOT operator, so "!b" will be true since b is initialized to 0. The "==" operator has higher precedence than the logical NOT operator, so "!b==a" is equivalent to "(!b) == a". Since !b is true and a is initialized to 0, the condition evaluates to true and the code inside the if statement is executed, which prints "Hello".

Submit
72. Find the correct Match
Submit
73. Choose the correct size of the datatypes for a 16bit system
Submit
74. Match properly
if one match is wrong, answer will be considered as wrong.if all matches are right, 2 marks will be given. Otherwise 0 (Zero) will be given
Submit
75. Match properly
if one match is wrong, answer will be considered as wrong.if all matches are right, 2 marks will be given. Otherwise 0 (Zero) will be given
Submit
76. Match properly
if one match is wrong, answer will be considered as wrong.if all matches are right, 2 marks will be given. Otherwise 0 (Zero) will be given
Submit
77. Class Department{    public Department(int deptCode, String deptName) {        System.out.print("Dept. Code "+deptCode+" "+deptName);    }}class CSE extends Department{    public CSE(){                }}class College {    public static void main(String... args) {        new CSE();    }}Write only missing statement to get output : Dept. Code 209 CSE

Explanation

The missing statement in the given code is "super(209, "CSE");". This statement is used to call the constructor of the superclass (Department) with the arguments 209 and "CSE". By including this statement in the constructor of the subclass (CSE), the output "Dept. Code 209 CSE" will be printed when the CSE object is created in the main method.

Submit
78. Write only output
class Department {     int code;    String name;     Department(int c, String n) {        code = c;        name = n;    }     Department[] getAll() {        Department cse = new Department(100, "CSE");        Department ce = new Department(101, "CE");        Department me = new Department(102, "ME");        Department ece = new Department(103, "ECE");        Department ee = new Department(104, "EE");         Department[] dept = {cse, ece, ee, ce, me};         return dept;    }} class College {     public static void main(String... args) {        for (Department d : new Department().getAll()) {            System.out.print(d.name.charAt(1));        }    }}

Explanation

The given code will result in an error because the getAll() method is being called on a new instance of the Department class, which does not have a constructor with no arguments. Therefore, when the for-each loop tries to iterate over the array returned by getAll(), it will throw an error.

Submit
79. Write only output
class Department {     int code;    String name;     Department(int c, String n) {        code = c;        name = n;    }     Department[] getAll() {        Department cse = new Department(100, "CSE");        Department ce = new Department(101, "CE");        Department me = new Department(102, "ME");        Department ece = new Department(103, "ECE");        Department ee = new Department(104, "EE");         Department[] dept = {cse, ece, ee, ce, me};         return dept;    }} class College {     public static void main(String... args) {        for (Department d : new Department().getAll()) {            System.out.print(d.name.charAt(1));        }    }}

Explanation

The code provided is incomplete and will result in a compilation error. The error occurs because the class Department does not have a default constructor, and in the College class, a new instance of Department is created without passing any arguments to the constructor. Therefore, the code will not compile and will produce an error.

Submit
View My Results

Quiz Review Timeline (Updated): Jun 19, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Jun 19, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Mar 15, 2016
    Quiz Created by
    Santanub
Cancel
  • All
    All (79)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Class Student {    private Student() {    } ...
Int a;a=scanf("%d",&a);​printf("%d",a);(user...
Int j,k,c=0;for(j=1;j<4;j++)for(k=0;k<4;k++) ...
Int a;a=scanf("%d",&a);​printf("%d",a);(user...
Class Student {    private Student() {    } ...
Write the output ...public class Cal {     int...
Write the output ... public class Cal {     int[]...
Write the output ... public class Cal {     int[]...
Write the output ... public class Cal {     int[]...
Class StaticTest {    static {       ...
Find the output ...class StaticTest {    static { ...
Class Game {     String title;    int...
Write only outputclass Department {     int code; ...
Class Department {     static void showName() { ...
Write only output ...class Department {     static void...
Write only output ...class Department {     static...
Write only output ... class Department{    void...
Class Department{    String...
Write the output ...public class Cal {     int...
Write the output ... public class Cal {     int[]...
Write the output ... public class Cal {     int[]...
Write the output ... public class Cal {     int[]...
Class StaticTest {    static {       ...
Find the output ...class StaticTest {    static { ...
Write only outputclass Department {     int code; ...
Write only output ...class Department {     static void...
Write only output ...class Department {     static...
Write only output ... class Department{    void...
Int a=500,b=300;if(!(a>b))   ...
What is the output of this C code?     #include...
Int a=500,b=300;if(!(a>b))   ...
Int a=4,b=2;if(a%2==0)  ...
What is the value of x in this C code?    #include...
If an exception is generated and there is no matching catch block,...
Int...
Int a=700;if(!a>400)   ...
Find output class System2 {    int opp(int a, int b)...
Int main(){int i = 10,*p;p= &i;printf("%u\n", p);}
Int a=1;printf("%d%d%d",a,a++,++a);output?
Int...
Find the output ...class Game {    public static void...
Public class Test {    int dis(int b){     ...
Int add(int x,int y){int z=(x+ ++y);return z ;}void main(){ int...
Int...
The output of the code below is     #include...
Int main(){int i = 10,*p = &i;printf("%d\n", *p);}
Int main(){int i = 10,*p;p= &i;printf("%d\n",...
Int i,n;scanf("%d",&n);for(i=1;i<=n;i++)  ...
What is the output of this C code?    #include ...
Which are true for variable length argument (modern approach)1. works...
Int...
What is the output of this C code?     #include...
Find output class System2 {    int opp(int a, int b)...
Int i=0;for(;i<=5;i++);   ...
What will be the output?#include<stdio.h>void...
Add(int,int);void main(){ int i=49,b;b= add(i,5)...
Int func(int);main(){int...
What is the output of this C code?     #include...
Subclasses catch exception as type of that class and also...
Int a=65;printf("%c",a);  output?​
Find outputclass System2 {    int d;  ...
What will be output of following c...
Find output class System {    int opp(int a, int b)...
Which are the correct variable name?(There can be more then...
Exception can be generated explicitly using key word throws
Float...
Int a=4.0,b=2.0;float c;c=b/a;printf("%f",c);output?
Find the true statement ...1. NullPointerException is checked...
Int...
Which are true1. members in interface are protected implicitly if...
Int a=0,b=0;if(!b==a)  ...
Find the correct Match
Choose the correct size of the datatypes for a 16bit system
Match properlyif one match is wrong, answer will be considered as...
Match properlyif one match is wrong, answer will be considered as...
Match properlyif one match is wrong, answer will be considered as...
Class Department{    public Department(int deptCode,...
Write only outputclass Department {     int code; ...
Write only outputclass Department {     int code; ...
Alert!

Advertisement