Java Junior

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Cvbee
C
Cvbee
Community Contributor
Quizzes Created: 1 | Total Attempts: 9,232
Questions: 59 | Attempts: 9,346

SettingsSettingsSettings
Java Junior - Quiz

It is created for Beginners in Java. This is to test the knowledge of any Java Developer wannabe.


Questions and Answers
  • 1. 

    If none of the private/protected/public is specified for a member, that member ...

    • A.

      Is accessible publicly

    • B.

      Is only accessible by other classes of the same package

    • C.

      Is only accessible from within the class

    • D.

      Is accessible by the class and its subclasses

    Correct Answer
    B. Is only accessible by other classes of the same package
    Explanation
    If none of the access modifiers (private, protected, public) is specified for a member, that member is only accessible by other classes of the same package. This means that the member can be accessed by any other class within the same package, but not by classes in different packages.

    Rate this question:

  • 2. 

    Which one is not correct?

    • A.

      A class needs to be instantiated as an object before being used

    • B.

      An objects exists in memory in run time

    • C.

      Class and object are just different names for the same thing

    • D.

      An object is a variable, where its type is the class used to declare the variable

    Correct Answer
    C. Class and object are just different names for the same thing
    Explanation
    The statement "Class and object are just different names for the same thing" is not correct. In object-oriented programming, a class is a blueprint or template for creating objects, while an object is an instance of a class. A class defines the properties and behaviors that an object will have, and multiple objects can be created from the same class. Therefore, a class and an object are not the same thing, but rather, a class is used to create objects.

    Rate this question:

  • 3. 

    Which is not a part of defining an object?

    • A.

      Description

    • B.

      Methods

    • C.

      Associations with other objects

    • D.

      Name

    Correct Answer
    A. Description
    Explanation
    An object in programming is typically defined by its name, methods, and associations with other objects. The description, on the other hand, is not a necessary component for defining an object. While a description can provide additional information about the object, it is not essential for its definition. The name is used to identify the object, methods define its behavior or actions, and associations establish relationships with other objects.

    Rate this question:

  • 4. 

    Class B inherits from Class A, what cannot be said:

    • A.

      B is a sub-class of A

    • B.

      A is a super-class of B

    • C.

      B has access to private members of A

    • D.

      B has access to protected members of A

    Correct Answer
    C. B has access to private members of A
    Explanation
    Since Class B inherits from Class A, it can access the protected and public members of Class A. However, it cannot access the private members of Class A. Private members are only accessible within the same class and not by any derived classes. Therefore, it cannot be said that B has access to the private members of A.

    Rate this question:

  • 5. 

    What is a member of a class

    • A.

      An attribute

    • B.

      A method

    • C.

      Attribute or method

    • D.

      A sub-class

    Correct Answer
    C. Attribute or method
    Explanation
    A member of a class refers to any attribute or method that belongs to that class. It can be either an attribute, which represents the data or state of the object, or a method, which represents the behavior or actions that the object can perform. In object-oriented programming, classes are used to define the blueprint for creating objects, and the members of a class define the characteristics and capabilities of those objects. Therefore, a member of a class can be either an attribute or a method.

    Rate this question:

  • 6. 

    A class is...

    • A.

      An object

    • B.

      An executable piece of code

    • C.

      An abstract definition of an object

    • D.

      A varibale

    Correct Answer
    C. An abstract definition of an object
    Explanation
    A class is an abstract definition of an object because it serves as a blueprint or template for creating specific instances of that object. It defines the properties and behaviors that the object will have, but it is not the actual object itself. The class provides a way to organize and structure the code, allowing for code reusability and modularity.

    Rate this question:

  • 7. 

    Which package do you need to use widgets such as JApplet, JFrame, JPanel and JButton?

    • A.

      Javax.swing

    • B.

      Javax.gui

    • C.

      Java.awt

    • D.

      Java.swing

    Correct Answer
    A. Javax.swing
    Explanation
    The correct answer is javax.swing. This is because javax.swing is the package that provides classes for creating and managing graphical user interface (GUI) components in Java. It includes classes such as JApplet, JFrame, JPanel, and JButton, which are commonly used for building GUI applications. The other options, javax.gui, java.awt, and java.swing, are not valid packages in Java.

    Rate this question:

  • 8. 

    Which one needs a web page to run

    • A.

      A Java Application

    • B.

      A Java Stand-Alone Application

    • C.

      A Java Applet

    • D.

      A Java Class

    Correct Answer
    C. A Java Applet
    Explanation
    A Java Applet needs a web page to run because it is a small application that is designed to be embedded within a web page. It is executed within a web browser's Java Virtual Machine (JVM) and requires the web page's HTML code to provide the necessary environment for its execution. Unlike Java Applications or Stand-Alone Applications, which can be run independently on a computer, a Java Applet relies on the web page infrastructure to function properly.

    Rate this question:

  • 9. 

    How to define a JButton with the caption test?

    • A.

      JButton aButton('test');

    • B.

      JButton aButton=new JButton("test");

    • C.

      JButton aButton=new JButton('test');

    • D.

      JButton("test") aButton;

    Correct Answer
    B. JButton aButton=new JButton("test");
    Explanation
    The correct answer is "JButton aButton=new JButton("test");". This is the correct way to define a JButton with the caption "test". In Java, when creating an object, the syntax is "new ClassName()", and in this case, the class name is JButton. The caption "test" is passed as a parameter within double quotes.

    Rate this question:

  • 10. 

    The last value in an array called ar can be found at index:

    • A.

      0

    • B.

      1

    • C.

      Ar.length

    • D.

      Ar.length - 1

    Correct Answer
    D. Ar.length - 1
    Explanation
    The last value in an array can be found at the index ar.length - 1 because arrays in most programming languages are zero-based, meaning the first element is at index 0. Therefore, the last element will be at the index one less than the length of the array.

    Rate this question:

  • 11. 

    What would display from the following statements? int [ ] nums = {1,2,3,4,5,6}; System.out.println((nums[1] + nums[3]));

    • A.

      6

    • B.

      2+4

    • C.

      1+3

    • D.

      4

    Correct Answer
    A. 6
    Explanation
    The code initializes an array called "nums" with the values {1,2,3,4,5,6}. It then prints the sum of the values at index 1 and index 3 of the array, which are 2 and 4 respectively. Therefore, the output will be 6.

    Rate this question:

  • 12. 

    What loop will display each of the numbers in this array on a separate line: float [ ] nums= {1.1f, 2.2f, 3.3f};

    • A.

      For (int i =0; i < 3; i++) System.out.println( nums[i]);

    • B.

      For (i = 1; i

    • C.

      For (i = 0; i

    • D.

      For (i = 1; i < 3; i++) System.out.println(nums[i]);

    Correct Answer
    A. For (int i =0; i < 3; i++) System.out.println( nums[i]);
    Explanation
    The correct answer is the first option, "for (int i =0; i < 3; i++) System.out.println( nums[i]);". This loop uses a for loop to iterate through the array "nums" and print each element on a separate line. The loop starts at index 0 and continues until the index is less than 3, incrementing the index by 1 each time. The "System.out.println(nums[i])" statement prints the element at the current index "i" in the array.

    Rate this question:

  • 13. 

    What displays from the following statements? String word = "abcde"; for (int i = 0; i <4; i+=2) System.out.print(word[i]);

    • A.

      Ab

    • B.

      Ac

    • C.

      Ace

    • D.

      Bd

    Correct Answer
    B. Ac
    Explanation
    The given code initializes a string variable "word" with the value "abcde". Then, it enters a for loop that starts with i=0 and increments i by 2 in each iteration until i

    Rate this question:

  • 14. 

    If we declare int [ ] ar = {1,2,3,4,5,6}; The size of array ar is:

    • A.

      0

    • B.

      5

    • C.

      6

    • D.

      7

    Correct Answer
    C. 6
    Explanation
    The size of the array "ar" is 6 because the given declaration "int[] ar = {1,2,3,4,5,6};" initializes an array named "ar" with 6 elements. Each element is assigned a value from 1 to 6. Therefore, the size of the array is equal to the number of elements in it, which is 6.

    Rate this question:

  • 15. 

    The following prototype shows that a Cylinder subclass is derived from a superclass called Circle

    • A.

      Class Circle extends Cylinder

    • B.

      Class Cylinder derived Circle

    • C.

      Class Cylinder extends Circle

    • D.

      Class Circle derived Cylinder

    Correct Answer
    C. Class Cylinder extends Circle
    Explanation
    The correct answer is "class Cylinder extends Circle". This is because the keyword "extends" is used to indicate that the class Cylinder is derived from the superclass Circle. In object-oriented programming, inheritance allows a subclass to inherit the properties and methods of its superclass, and in this case, the subclass Cylinder is inheriting from the superclass Circle.

    Rate this question:

  • 16. 

    With inheritance, a derived subclass object can directly access any

    • A.

      Public or private superclass member

    • B.

      Private superclass member

    • C.

      Public superclass member (and protected subclass members if it's in the same package)

    • D.

      Protected, public or private superclass member

    Correct Answer
    C. Public superclass member (and protected subclass members if it's in the same package)
    Explanation
    Inheritance allows a derived subclass object to directly access public superclass members. Additionally, if the subclass is in the same package as the superclass, it can also access protected subclass members. However, private superclass members cannot be accessed by the subclass. Therefore, the correct answer is that a derived subclass object can directly access public superclass members and protected subclass members if it's in the same package.

    Rate this question:

  • 17. 

    What is the role of the constructor? 

    • A.

      Create an instance of a class (an object)

    • B.

      Create names for methods

    • C.

      To create some type of change in the state of an object

    Correct Answer
    A. Create an instance of a class (an object)
    Explanation
    Constructors have one purpose in life: to create an instance of a class. This can also be called creating an object.

    Rate this question:

  • 18. 

    A class cannot be declared:

    • A.

      Static

    • B.

      Private

    • C.

      Protected

    Correct Answer
    A. Static
    Explanation
    There is no access modifier called "static" for class declarations in Java. "Static" is used for static members and methods within a class. So, a class cannot be declared as "static," but it can have static members or methods.

    Rate this question:

  • 19. 

    Following code will result in: int num = 6.7;

    • A.

      Compilation error

    • B.

      Runtime error

    • C.

      Num being 6.7

    • D.

      Num being 6

    Correct Answer
    A. Compilation error
    Explanation
    The given code will result in a compilation error. This is because the variable "num" is declared as an integer, but it is being assigned a floating-point value (6.7). In Java, you cannot assign a floating-point value to an integer variable without explicit type casting.

    Rate this question:

  • 20. 

    Following code will result in: int a1 = 5; double a2 = (float)a1;

    • A.

      Compilation error

    • B.

      Runtime error

    • C.

      No errors

    • D.

      Runtime Exception

    Correct Answer
    C. No errors
    Explanation
    The given code will not result in any errors. It initializes an integer variable "a1" with the value 5 and then assigns the value of "a1" to a double variable "a2" after casting it to a float. Since both int and float can be implicitly converted to double without any loss of precision, there will be no compilation or runtime errors.

    Rate this question:

  • 21. 

    Following code will result in: int num = 8/0;

    • A.

      Compilation error: Divisions must be in a try block

    • B.

      Compilation error: DivideByZeroException

    • C.

      Runtime Exception

    • D.

      No Error: a is NaN

    Correct Answer
    C. Runtime Exception
    Explanation
    The code will result in a runtime exception because it is trying to divide a number by zero, which is not allowed in mathematics. This will cause a runtime error and the program will terminate abruptly.

    Rate this question:

  • 22. 

    Following code will result in: float num = 5/0;

    • A.

      Compilation error: Divisions must be in a try block

    • B.

      Compilation error: DivideByZeroException

    • C.

      Runtime Exception

    • D.

      No Error: a is NaN

    Correct Answer
    C. Runtime Exception
    Explanation
    The code will result in a runtime exception because dividing a number by zero is not a valid operation in mathematics. This will throw an exception at runtime and the program will terminate abruptly.

    Rate this question:

  • 23. 

    A class can be transient

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    A class cannot be transient. The "transient" keyword in programming is used to indicate that a variable should not be serialized when an object is being converted to a byte stream. However, it cannot be applied to a class itself. The "transient" keyword can only be used with variables within a class to specify that they should not be included in the serialization process. Therefore, the statement that a class can be transient is incorrect.

    Rate this question:

  • 24. 

    Following code will result in: class A { int x = 1; public static void main(String [] args) { System.out.println("x is " + x); }}

    • A.

      Compilation error

    • B.

      Runtime Error

    • C.

      Runtime Exception

    • D.

      Output of x is 1

    Correct Answer
    A. Compilation error
    Explanation
    The code will result in a compilation error because the variable "x" is not declared as static, which means it can only be accessed through an instance of the class. However, in the main method, which is static, there is no instance of the class A created to access the variable "x". Therefore, a compilation error will occur when trying to access the non-static variable from a static context.

    Rate this question:

  • 25. 

    Following code will result in: class A { public static void main(String [] args) {B b = new A(); }} class B extends A {}

    • A.

      Compile error

    • B.

      Runtime Exception

    • C.

      No error

    • D.

      No Output

    Correct Answer
    A. Compile error
    Explanation
    The given code will result in a compile error because the object 'b' is being declared as type 'B' but it is being assigned a new instance of class 'A'. Since 'A' is not a subclass of 'B', this assignment is not valid and will cause a compile error.

    Rate this question:

  • 26. 

    Following code will result in: class A { public static void main(String [] args) {A a = new B(); }} class B extends A {}

    • A.

      Compiler error

    • B.

      Runtime Exception

    • C.

      No errors

    • D.

      Output is B

    Correct Answer
    C. No errors
    Explanation
    The code will not result in any errors because class B extends class A, so it is valid to assign an instance of B to a variable of type A. The code will compile successfully and run without any issues.

    Rate this question:

  • 27. 

    Methods that are marked protected can be called in any subclass of that class.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Protected methods in a class can be accessed and called by any subclass of that class. This access modifier allows subclasses to inherit and use the protected methods from the parent class. It provides a level of accessibility that is more restricted than public, but less restricted than private. Therefore, the statement that protected methods can be called in any subclass of the class is true.

    Rate this question:

  • 28. 

    An abstract class can have non-abstract methods.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    An abstract class can have non-abstract methods because an abstract class is a class that cannot be instantiated and is meant to be inherited by other classes. It can contain both abstract and non-abstract methods. Non-abstract methods in an abstract class have a complete implementation and can be directly used by the subclasses that inherit from the abstract class. This allows the abstract class to provide common functionality to its subclasses while still allowing them to implement their own specific behavior.

    Rate this question:

  • 29. 

    Java keywords are written in lowercase as well as uppercase.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    Java keywords are written in lowercase only. In Java, keywords are predefined reserved words that have specific meanings and cannot be used as identifiers for variables, methods, or classes. These keywords are case-sensitive, meaning that they must be written in lowercase letters. Writing keywords in uppercase would result in a compilation error. Therefore, the statement that Java keywords are written in lowercase as well as uppercase is incorrect.

    Rate this question:

  • 30. 

    What is an instanceof?

    • A.

      A methods in object

    • B.

      An operator and keyword

    • C.

      An operator only

    • D.

      A keyword only

    Correct Answer
    B. An operator and keyword
    Explanation
    The correct answer is "An operator and keyword". The instanceof operator is used to check if an object belongs to a particular class or interface. It returns true if the object is an instance of the specified class or interface, or one of its subclasses or implementations. The instanceof keyword is used in Java programming language to perform this check. Therefore, the answer "An operator and keyword" accurately describes the instanceof operator.

    Rate this question:

  • 31. 

    Primitive datatypes are allocated on a stack.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Primitive datatypes are allocated on a stack because they are simple and small in size. The stack is a region of memory that is used for local variables and function calls. When a primitive datatype is declared, memory is allocated on the stack to store its value. The stack is a fast and efficient way to allocate and deallocate memory for these types of variables.

    Rate this question:

  • 32. 

    Can you compare a boolean to an integer?

    • A.

      Yes

    • B.

      No

    Correct Answer
    B. No
    Explanation
    A boolean is a data type that can only have two possible values: true or false. An integer, on the other hand, is a numeric data type that represents whole numbers. Since they are different data types, they cannot be directly compared.

    Rate this question:

  • 33. 

    If class A implements an interface does it need to implement all methods of that interface?

    • A.

      Yes, always.

    • B.

      No, not when A is abstract

    Correct Answer
    B. No, not when A is abstract
    Explanation
    When a class A is declared as abstract, it means that it cannot be instantiated directly and can only be used as a base class for other classes. In this case, if class A implements an interface, it is not required to implement all the methods of that interface. The responsibility of implementing those methods is passed on to the concrete subclasses of A. Therefore, the correct answer is "No, not when A is abstract."

    Rate this question:

  • 34. 

    Integer a = new Integer(2); Integer b = new Integer(2); What happens when you do if (a==b)?

    • A.

      Compiler error

    • B.

      Runtime Exception

    • C.

      True

    • D.

      False

    Correct Answer
    D. False
    Explanation
    When comparing the objects "a" and "b" using the "==" operator, it checks if the two objects refer to the same memory location. In this case, even though the values of "a" and "b" are both 2, they are different objects with different memory locations. Therefore, the condition "a==b" evaluates to false.

    Rate this question:

  • 35. 

    The methods wait(), notify() and notifyAll() in Object need to be called from synchronized pieces of code.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The methods wait(), notify(), and notifyAll() in the Object class need to be called from synchronized pieces of code because they are used for inter-thread communication and synchronization. When a thread calls the wait() method, it releases the lock on the object and waits for another thread to notify it. Similarly, when a thread calls the notify() or notifyAll() method, it notifies the waiting threads that they can resume execution. To ensure thread safety and prevent race conditions, these methods should only be called from synchronized blocks or methods.

    Rate this question:

  • 36. 

    Inner classes can be defined within methods.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Inner classes can be defined within methods. This statement is true. In Java, it is possible to define a class inside another class, and this inner class can also be defined within a method. This allows for more flexibility in organizing and encapsulating code. Inner classes have access to the variables and methods of the outer class, and can be useful in implementing complex logic or creating specialized data structures within a specific method scope.

    Rate this question:

  • 37. 

    Synchronized is a keyword to tell a Thread to grab an Object lock before continuing execution.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The explanation for the given correct answer is that the "synchronized" keyword in Java is used to ensure that only one thread can access a block of code or a method at a time. It provides a way to synchronize the execution of multiple threads, preventing them from interfering with each other. When a thread encounters a synchronized block or method, it grabs the lock on the associated object and continues execution. This ensures that other threads have to wait until the lock is released before they can access the synchronized code. Therefore, the statement that "synchronized is a keyword to tell a Thread to grab an Object lock before continuing execution" is true.

    Rate this question:

  • 38. 

    The default statement of a switch is always executed.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    The default statement of a switch is not always executed. The default statement is only executed when none of the cases match the value being evaluated. If a case matches, the corresponding block of code is executed and the switch statement terminates. If there is no default statement, and none of the cases match, the switch statement simply does nothing. Therefore, the correct answer is false.

    Rate this question:

  • 39. 

    How can you prevent a member variable from becoming serialized?

    • A.

      By marking it private

    • B.

      By marking it volatile

    • C.

      By marking it transient

    • D.

      You can not.

    Correct Answer
    C. By marking it transient
    Explanation
    A transient variable is a variable that may not be serialized.

    Rate this question:

  • 40. 

    What is the keyword used in java to create an object?

    • A.

      This

    • B.

      New

    • C.

      Sync

    • D.

      New()

    Correct Answer
    B. New
    Explanation
    In Java, the keyword "new" is used to create an object. It is followed by the name of the class and parentheses, which can optionally contain arguments to be passed to the constructor of the class. The "new" keyword dynamically allocates memory for the object and initializes its state.

    Rate this question:

  • 41. 

    What is the correct syntax for java main method?

    • A.

      Public void main(String[] args)

    • B.

      Public static void main(string[] args)

    • C.

      Public static void main()

    • D.

      None of the above

    Correct Answer
    D. None of the above
    Explanation
    public static void main(String args[]) is the right format. String instead of string is the correct one.

    Rate this question:

  • 42. 

    A null reference may be used to access a static variable or method.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    A null reference cannot be used to access a static variable or method because static members belong to the class itself and not to any specific instance of the class. They can be accessed using the class name directly, without needing an instance of the class. A null reference represents the absence of an object and cannot be used to access any members, including static members. Therefore, the statement is false.

    Rate this question:

  • 43. 

    Native methods can be 'abstract'

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    Native methods cannot be abstract. Native methods are methods that are implemented in a language other than Java, such as C or C++. These methods are declared with the "native" keyword and their implementation is provided outside of the Java code. Abstract methods, on the other hand, are methods that are declared without an implementation and must be implemented by the subclasses. Since native methods already have a specific implementation in a different language, they cannot be declared as abstract. Therefore, the correct answer is False.

    Rate this question:

  • 44. 

    Which of the following is not a Java keyword?

    • A.

      Main

    • B.

      Try

    • C.

      Integer

    • D.

      String

    Correct Answer
    C. Integer
    Explanation
    "main" is a keyword used to denote the entry point of a Java program.
    "try" is a keyword used to start a block of code that might cause exceptions.
    "String" is a keyword used to declare string variables and objects.
    "integer" is not a keyword in Java. The correct keyword for integer data types in Java is "int."

    Rate this question:

  • 45. 

    What is an Applet ?

    • A.

      A Java program that does not run through a web browser

    • B.

      A Java program that is run through a web browser

    • C.

      An object-oriented programming language

    • D.

      An interactive website

    Correct Answer
    B. A Java program that is run through a web browser
    Explanation
    An applet is a Java program that is designed to run within a web browser. It is a small application that is embedded within a web page and can be executed by a Java Virtual Machine (JVM) installed on the client's machine. Applets are used to add interactive features to websites and provide dynamic content. They have access to certain resources on the client's machine, such as the file system, but are restricted from performing certain actions for security reasons.

    Rate this question:

  • 46. 

    Java runs on _______.

    • A.

      Windows

    • B.

      Unix/Linux

    • C.

      Mac

    • D.

      All of the Above

    Correct Answer
    D. All of the Above
    Explanation
    Java is a platform-independent programming language, which means it can run on multiple operating systems. It is designed to be compatible with Windows, Unix/Linux, and Mac operating systems. Therefore, the correct answer is "All of the Above" as Java can run on all of these platforms.

    Rate this question:

  • 47. 

    What's the difference between an Applet and an application ?

    • A.

      None of the above.

    • B.

      Applets are run over the web.

    • C.

      Applets can paint words, applications cannot.

    • D.

      An application is only available on Windows

    Correct Answer
    B. Applets are run over the web.
    Explanation
    An applet is a small program that is designed to be executed within a web browser. It is typically written in Java and runs on the client-side. On the other hand, an application is a standalone program that is designed to be executed on a computer's operating system. It is not limited to running within a web browser. Therefore, the difference between an applet and an application is that applets are specifically designed to be run over the web, while applications can be run on any operating system.

    Rate this question:

  • 48. 

    What is the main function of any variable ?

    • A.

      To add numbers together

    • B.

      To keep track of data in the memory of the computer

    • C.

      To print words on the screen

    • D.

      To write Java codes

    Correct Answer
    B. To keep track of data in the memory of the computer
    Explanation
    The main function of any variable is to keep track of data in the memory of the computer. Variables are used to store and manipulate data in computer programs. They allow us to assign values to data and retrieve or modify those values as needed. By storing data in variables, we can access and manipulate it throughout the program, making it an essential component of computer programming.

    Rate this question:

  • 49. 

    What is the proper way to declare a variable ?

    • A.

      VariableName variableType;

    • B.

      VariableName;

    • C.

      VariableType;

    • D.

      VariableType variableName;

    Correct Answer
    D. VariableType variableName;
    Explanation
    The proper way to declare a variable is by specifying the variable type followed by the variable name. This allows the compiler to allocate the appropriate amount of memory for the variable and ensures that the variable can be used correctly in the program.

    Rate this question:

  • 50. 

    What is an assignment statement ?

    • A.

      Adding a number to an int

    • B.

      Assigning a multiplication

    • C.

      Assigning a name to a variable

    • D.

      Assigning a value to a variable

    Correct Answer
    D. Assigning a value to a variable
    Explanation
    An assignment statement is a programming construct that assigns a value to a variable. It is used to store and update data in a program. In this context, assigning a value to a variable means giving a specific value to a variable so that it can be used later in the program. This is a fundamental concept in programming as it allows for the manipulation and storage of data.

    Rate this question:

Quiz Review Timeline +

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

  • Current Version
  • Feb 07, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Nov 11, 2013
    Quiz Created by
    Cvbee
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.