Site icon DataFlair

Quiz on Java Variables

quiz on java variables

Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java

Variables are the heart of any Java program, holding the data that breathes life into your code. But how well do you understand their nuances and how to use them effectively? Put your knowledge to the test with this engaging quiz that covers fundamental concepts of variables in Java.

Whether you’re a beginner taking your first steps or a seasoned developer looking to solidify your understanding, this quiz will challenge and enlighten you. Prepare to dive deep into a variable declaration, scope, data types, initialization, and more! Let’s test your knowledge.

Time limit: 0

Quiz Summary

0 of 15 Questions completed

Questions:

Information

You have already completed the quiz before. Hence you can not start it again.

Quiz is loading…

You must sign in or sign up to start the quiz.

You must first complete the following:

Results

Quiz complete. Results are being recorded.

Results

0 of 15 Questions answered correctly

Your time:

Time has elapsed

You have reached 0 of 0 point(s), (0)

Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)

Categories

  1. Not categorized 0%
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  1. Current
  2. Review / Skip
  3. Answered
  4. Correct
  5. Incorrect
  1. Question 1 of 15
    1. Question

    What is the line missing in the following code ?

    public class Sample {

        public void Demo ()

        {

            int a = 0;

            int b = a + 5;

            System.out.println(“B value is: ” + b);

        }

        public static void main (String args [])

        {

            Sample obj = new Sample ();

        }

    }

    Correct
    Incorrect
  2. Question 2 of 15
    2. Question

    What is the error in the program?

    class demo {

    public static void main ( String args [] )

    {

    int a;

    system.out.println(“Variable value is” + a );

    }

        }

    Correct
    Incorrect
  3. Question 3 of 15
    3. Question

    What will be the output of the program?

    class factorial {

    public static void main ( String args [] )

    {

    int n = 10 , fact = 1;

    for ( i = 1 , i < n , i++ )

    {

    fact = fact*i;

    }

    system.out.println(  “ Factorial of the program is “ + fact );

    }

    }

    Correct
    Incorrect
  4. Question 4 of 15
    4. Question

    If the entered number is 10. How many times will the for loop be executed?

    class loopexample {

    public static void main {

    int n , sum = 0 ;

    Scanner sc = new Scanner(System.in);

    system.out.println( “ Enter a number ” );

    n = sc.nextint();

    for( int i = n , i = 0 , i– )

    {

    sum = sum + i )

    }

    system.out.println(“ The sum of “ + n + “ natural numbers is “ + sum );

    }

    }

    Correct
    Incorrect
  5. Question 5 of 15
    5. Question

    Which of the following is not a correct syntax of a variable name?

    Correct
    Incorrect
  6. Question 6 of 15
    6. Question

    The above given program is an example of which type of Variable?

    public class variableDemo

    public void add()

    {

    int num = 0;

    num = num + 7;

    System.out.println(“The number is : ” + num);

    }

    public static void main( String args [] ) 

    {

    VariableDemo obj = new VariableDemo();

    obj.add(8);

    }

    }

    Correct
    Incorrect
  7. Question 7 of 15
    7. Question

    What will be the output of the program?

     public class InstanceVariableExample {

         public static void main( String args [] ) 

    {

                 Employee employee = new Employee();

            System.out.println(employee.companyName);

            System.out.println(employee.branches);

            System.out.println(employee.noofemp);

            employee.companyName = “DataFlair”;

            employee.branches = 10;

            employee.noofemp = 28;

         }

    }

     

    class Employee {

        public int branches;

        public String companyName;

        public int noofemp;

    }

    Correct
    Incorrect
  8. Question 8 of 15
    8. Question

    What will be the output of the program?

    public class VariableExample{

        static int data = 30;

       

       public static void main( String args [] )

    {  

          VariableExample obj = new VariableExample();

          System.out.println( VariableExample.data);

       }

    }

    Correct
    Incorrect
  9. Question 9 of 15
    9. Question

    When will a variable be destroyed?

    Correct
    Incorrect
  10. Question 10 of 15
    10. Question

    How could a variable space be destroyed from the memory?

    Correct
    Incorrect
  11. Question 11 of 15
    11. Question

    What happens to variable a in this program?

    class example{

    public static void main ( String args [] )

    {

    int a;

    a = 10;

    system.out.println(“Value of variable a is “ + a );

    a = null;

    }

    }

    Correct
    Incorrect
  12. Question 12 of 15
    12. Question

    How to call a garbage collector meanwhile in a program?

    Correct
    Incorrect
  13. Question 13 of 15
    13. Question

    What will be the output of the program?

     class typecastexample {

    public static void main ( String args [] )

    {

    int i,j,k;

    i = 11;

    j = 12;

    k = (float) i/j;

    system.out.println(k);

    }

    }

    Correct
    Incorrect
  14. Question 14 of 15
    14. Question

    Why is the highlighted line used in this program?

    public class demoprogram {

    public static void main( String args [] ) 

    {

                 int x = 99;

                 System.out.println(((Object)x).getClass().getSimpleName());

                }

         }

    Correct
    Incorrect
  15. Question 15 of 15
    15. Question

    What can be done to change a variable to a constant?

     

    Correct
    Incorrect

Summary:

Congratulations on completing the Java Variables Quiz! Take a moment to reflect on the concepts you’ve explored and identify any areas where you’d like to deepen your understanding. Remember, variables are foundational building blocks in Java, and a strong grasp of them is essential for crafting effective code.

Continue your journey by exploring additional resources, practising regularly, and engaging with the vibrant Java community. The path to Java mastery awaits!

Exit mobile version