Class 8 chapter 5

 ### Complete Java Chapter – All Questions with Answers


Here are all the questions and answers from both textbook pages, arranged section-wise for easy study and exam preparation.


### A. Multiple Choice Questions (MCQs)


1\. Which of the following is not a valid starting character for a Java identifier?


a. _ b. $ c. 7 d. A


Answer: c. 7


2\. The System.out.println() statement is used for:


a. Reading input from the user b. Performing calculations c. Displaying output on the console d. Declaring variables


Answer: c. Displaying output on the console


3\. What is the process of assigning an initial value to a variable called?


a. Declaration b. Initialization c. Execution d. Compilation


Answer: b. Initialization


### B. Fill in the Blanks


Word Bank: Data type, void, Assignment, IDE, Identifiers


* BlueJ is an IDE designed for beginners to write, edit, and execute Java programs.


* Java components like variables, methods, and classes are given names called Identifiers.


* The main() method is defined as public static with a void return type.


* The += operator is an example of an Assignment operator.


* char is a Data type.


### C. State Whether the Statements Are True or False


1. Keywords are the words that have already been defined by a Java compiler.


Answer: True


2. In BlueJ, you should compile your code before running it.


Answer: True


3. The && (Logical AND) operator returns true if at least one of the conditions is true.


Answer: False


Correct statement: The && operator returns true only if both conditions are true.


4. An object is a blueprint or template for creating classes.


Answer: False


Correct statement: A class is a blueprint or template for creating objects.


5. The System.out.print() statement prints output and then moves to the next line.


Answer: False


Correct statement: System.out.println() moves to the next line, whereas System.out.print() does not.


### D. Find the Final Value


Question: What will be the final value of the finalValue variable after the following Java expression is evaluated?


```java

int finalValue = 30 + 10 / 2 - 4 * 3 % 5;

```


Options:


a. 33 b. 25 c. 65 d. 39


Correct Answer: a. 33


Solution:


Step 1: 10 / 2 = 5


Step 2: 4 × 3 = 12


Step 3: 12 % 5 = 2


Step 4: 30 + 5 − 2 = 33


Therefore, the final value is 33.


### E. Write a Basic Java Code


1\. Write a Java program to add two numbers and display the result.


Answer:


```java

class Addition

{

    public static void main(String[] args)

    {

        int a = 10;

        int b = 20;


        int sum = a + b;


        System.out.println("Sum = " + sum);

    }

}

```


Output:


```text

Sum = 30

```


2\. Write a Java program to display the following output: Hello, Students! Welcome to Java programming!


Answer:


```java

class Welcome

{

    public static void main(String[] args)

    {

        System.out.println("Hello, Students! Welcome to Java programming!");

    }

}

```


Output:


```text

Hello, Students! Welcome to Java programming!

```


### F. Answer the Following


1\. Explain the concept of Abstraction in OOP with an example.


Answer:


Abstraction is an important concept of Object-Oriented Programming (OOP). It means hiding unnecessary details and showing only the essential features of an object to the user.


Example: When we drive a car, we use the steering wheel, brake and accelerator without knowing how the engine works internally.


2\. Differentiate between System.out.print() and System.out.println().


Answer:


| System.out.print() | System.out.println() |

| ------------------------------------------------ | ------------------------------------------- |

| Displays output without moving to the next line. | Displays output and moves to the next line. |

| The next output appears on the same line. | The next output appears on a new line. |


Example:


```java

System.out.print("Hello");

System.out.print("Students");

```


Output:


```text

HelloStudents

```


Using println():


```java

System.out.println("Hello");

System.out.println("Students");

```


Output:


```text

Hello

Students

```


3\. How does a class relate to an object in OOP?


Answer:


A class is a blueprint or template used to create objects. An object is an instance of a class. A class defines the properties and methods, while an object uses them.


Example:


* Class: Car


* Objects: BMW, Audi, Honda.


4\. Explain class declaration with an example.


Answer:


Class declaration is the process of defining a class in Java using the `class` keyword, followed by the class name and its body.


Example:


```java

class Student

{

    int rollNo;

    String name;


    void display()

    {

        System.out.println(name);

    }

}

```


Here:


* Student is the class name.


* rollNo and name are variables.


* display() is a method.


5\. What are operators? Explain any two operators with examples.


Answer:


Operators are special symbols used to perform operations on variables and values in Java.


1\. Arithmetic Operators: These operators are used to perform mathematical calculations such as addition, subtraction, multiplication and division.


Example:


```java

int a = 10, b = 5;

System.out.println(a + b);

```


Output:


```text

15

```


2\. Relational Operators: These operators are used to compare two values. They return either true or false.


Example:


```java

int a = 10, b = 5;

System.out.println(a > b);

```


Output:


```text

true

```


### G. Important Questions for Quick Revision


| No. | Question | Answer |

| --- | -------------------------------------- | -------------------------- |

| 1 | What is BlueJ? | IDE |

| 2 | What are Java names called? | Identifiers |

| 3 | What is the return type of main()? | void |

| 4 | What is +=? | Assignment operator |

| 5 | What is char? | Data type |

| 6 | What is a class? | Blueprint of an object |

| 7 | What is an object? | Instance of a class |

| 8 | What is abstraction? | Hiding unnecessary details |

| 9 | Which statement displays output? | System.out.println() |

| 10 | Which operator represents Logical AND? | && |

| 11 | Which keyword declares a class? | class |

| 12 | Which symbol represents addition? | + |


### H. Important Java Operators


| Operator | Name | Example |

| -------- | -------------- | --------------- |

| + | Addition | 10 + 5 = 15 |

| - | Subtraction | 10 - 5 = 5 |

| * | Multiplication | 10 * 5 = 50 |

| / | Division | 10 / 5 = 2 |

| % | Modulus | 10 % 3 = 1 |

| > | Greater than | 10 > 5 |

| < | Less than | 5 < 10 |

| == | Equal to | 5 == 5 |

| && | Logical AND | true && true |

| \|\| | Logical OR | true \|\| false |


### Exam preparation checklist


Your preparation


0/7 completed


Learn all MCQ answers


Practise all five fill-in-the-blanks


Revise True/False statements


Understand the final value calculation


Practise both Java programs


Learn all five descriptive answers


Revise Java operators


Study tip: First learn the definitions, then practise the Java programs by writing them yourself. This will help you prepare for both theory and practical questions.


Comments

Popular posts from this blog

CLASS 3 REVISION

CLASS V