Page 291 - CA_Blue( J )_Class10
P. 291

Member methods
                       void input()          :  Inputs the word
                       void count_vowels()    :   Counts the number of vowels and assigns to vc
                       void count_consonants()   :  Counts the number of consonants and assign to cc
                       void display()         :  Prints the word, number of vowels and consonants

                 C.  Assertion and Reasoning based questions.
                         The following questions consist of two statements – Assertion (A) and Reason (R). Answer these questions by selecting the
                       appropriate option given below:
                       a.  Both A and R are true, and R is the correct explanation of A.
                       b.  Both A and R are true, but R is not the correct explanation of A.
                       c.  A is true, but R is false.
                       d.  A is false, but R is true.
                    1.  Assertion (A): A class can have multiple class variables.
                        Reason (R): All instances of a class stores the same value.
                    2.  Assertion (A): In object-oriented programming, methods defined in a class can only access the data of that specific class instance.
                        Reason (R): This ensures that the data of one instance cannot be accidentally modified by methods operating on another instance.
                    3.  Assertion (A): Abstraction allows focusing on how an object does what it does rather than what it does.
                        Reason (R): Abstraction is achieved by using abstract classes and interfaces that define the methods a class must implement
                       without providing the method's implementation.
                    4.  Assertion (A): A constructor is used to initialize objects of a class.
                        Reason (R): A constructor is a special method that is called automatically when an object is created.

                                                                                                  21 st
                 D.  Case-based questions.                                                     Century   #Experiential Learning
                                                                                                 Skills
                        Ajay is a software developer working on a project to create a system for managing a small online bookstore. He decides to use
                       object-oriented programming in Java to structure his code. Ajay starts by defining a class called Book to represent the books in the
                       store. He includes several components in this class, such as attributes, methods, a constructor, and encapsulation techniques.
                        Here’s the initial version of Sarah’s Book class in Java:
                       class Book {
                          static String bookstoreName = "Online Book";
                           String title;
                           String author;
                           double price;
                           Book(String title, String author, double price)
                       {
                               this.title = title;
                               this.author = author;
                               this.price = price;
                           }

                           void displayDetails()
                        {
                               System.out.println("Title: " + title + ", Author: " + author + ", Price: Rs." +
                       price);
                           }
                           void applyDiscount(double discount)
                       {
                               this.price -= discount;
                           }
                       }

                                                                                                                       289
                                                                                      Class as the Basis of all Computation  289
   286   287   288   289   290   291   292   293   294   295   296