Sayantan Mazumdar_Class X ICSE_Revision Chapter_SAQ.pdf.PDF

Full Transcript

Sayantan Mazumdar-Class X ICSE-Revision Chapter-SAQ SOLVED QUESTIONS [Short Answer Type Questions] 1. What is object-oriented programming? Ans. Object-oriented programming simulates the real world in softwa...

Sayantan Mazumdar-Class X ICSE-Revision Chapter-SAQ SOLVED QUESTIONS [Short Answer Type Questions] 1. What is object-oriented programming? Ans. Object-oriented programming simulates the real world in software. Real world consists of objects. 2. Name two Process Oriented languages and two Object Oriented languages. Ans. Two Process Oriented Languages are: C and Fortran Two Object Oriented Languages are: C+ + and Java 3. Name any two principles/characteristics of Object Oriented Programs. Ans. Some of the basic principles of object-oriented programming are: Encapsulation, Abstraction, Inheritance and Polymorphism are the principles of OOP. 4. Write the usage of different OOPs concepts. Ans. Use of encapsulation: Encapsulation leads to abstraction and hence protects the object from misuse. Use of Abstraction: Prevents the object from mishandling and misuse. Use of Inheritance: The derived class inherits the features, better called members of the base class. Hence, there is no need of defining them again in the sub class. Use of polymorphism: In Java, polymorphism concept is implemented as method/function overloading. With the same function name, different behaviours’ are provided. 5. Define the term Bytecode. Ans. Java programs are both compiled [i.e. translation of ail instructions of the source program(java program) to machine language at one go.] and interpreted [mean translation of instructions one by one]. The java compiler translates the source code to an intermediate level language called bytecode. It is independent of the machine on which the program is run. The same byte code file can be used by any system. 6. Differentiate between POP and OOP. Procedural Oriented Programming Language Object Oriented Programming Language 7. What is the need of JVM? Ans. To run a Java program written on another system, its bytecode needs to be transferred to its own Java Virtual Machine. JVM is an interpreter which translates the program to specific machine language and runs it to give the result. 8. Explain the compilation process/execution stages in Java. Ans. Compilation Process/Execution Stages in Java. Java programs are both compiled and interpreted. The Java compiler translates the source code to an intermediate level language called bytecode. It is independent of the machine on which the program is run. The same bytecode file can be used by any system. Sayantan Mazumdar-Class X ICSE-Revision Chapter-SAQ To run a java program written on another system, its bytecode needs to be transferred to its own Java Virtual Machine. JVM is an interpreter which translates the program to its own machine language and Execution stages of Java bytecode 9. What features of Java have made it so popular that a need has been felt to introduce it at beginners level? level? Ans. Features of Java making it so popular: (A) It is a purely object-oriented programming language. (B) It can be used to build distributed application i.e. data or resources can be accessed from any networked computer easily. (C) Java programs are both compiled and interpreted. (D) Java programs are portable, i.e., can be carried to different machines in the foim of bytecode. (E) Java programs can handle unexpected faults and errors. (F) Java performs type checking on the user machine. On the net, while the programs are transferred, any changes occurring in the program arc trapped as errors. (G) It allows to perform many tasks at the same time. 10. List and explain all characteristics of an object-oriented programming. Ans. (A) Abstraction. Abstraction is a concept of hiding unnecessary details and representing only the very essential features. For example, the details of the structure and circuit of a television is hidden and only the essential components like the power /push button , volume , brightness and contrast control and channel changer keys are available for us to use. Humans can easily manage the complexities of the systems through abstraction. (B) Encapsulation. Binding and wrapping up the methods and the data (on which the method is applied) together is called encapsulation. It keeps them safe from being misused or mishandled. (C) Inheritance. Inheritance is the process by which an object acquires the properties of another object. For example , Alsatian is a part of the classification dog , which itself is a part of mammal class and this mammal class is under the class animal. Here, Alsatian inherits the characteristics of dog, dog inherits the characteristics of mammal and mammal inherits the characteristics of animal class. (D) Polymorphism. It means that the same operation /function may behave differently on different classes, For example, the operation move behaves differently when applied to a Microsoft Windows than when applied to a chess game. 11. Why is Java called Internet language? Ans. Java programs are translated to java bytecode. Since bytecode is not affected by the machine environment, it is easier to run these programs on a wide range of machines. Only a java interpreter JVM is required to be implemented on the machines. JVM along with the java Application Interface libraries acts as a platform for the java programs to run on the machine. All JVM’s interpret the same bytecode. This makes the program easier to be transported to variety of machines thus making it portable. The worldwide web on the internet demands portable programs as of java, to be distributed on the internet. The second reason for its popularity as an internet language is that it concentrates on the real world objects. Sayantan Mazumdar-Class X ICSE-Revision Chapter-SAQ 12. Differentiate between a class and an object. Ans. Class Object Class is a blueprint or template from which objccts Object is an instance of a class. are created. Class has logical existence. Object has physical existence. For class, memory space is not allocated, when it is In case of an object memory space is allocated, created. when it is created. Class is declared once. Object is created many times. Class is declared using the keyword 'class. Object is created through the keyword 'new'. 13. Why is a class called an object factory? Ans. Each class describes possibly an infinite set of individual objects. So, it can be called as a factory of objects. For example, a class of cellphone can have numerous objects as Nokia, Samsung, Panasonic, etc. The features and functions of the objects are described within the class. 14. How to create an object in Java? Ans. An object is created from aclass. In Java, the new key word is used to create new object. For example: prog1 objl= new prog1() Where prog1 is the class, obj1 is the newly created object's name and prog1() is the constructor of the class. 15. Why is an object cailed “an instance of a class"? Ans. A class encapsulates the data members and member functions. It is used to create an object. A class is an object factory. Hence, an object is called an instance of a class. 16. Why is a class known as composite data type? Ans. A class is called a composite data type because it binds up (encapsulates) one or more primitive types together as a single data type. e.g., class { Abc int x; float y; 17.What is the difference between Unicode and ASCII ? Ans. Unicode is a superset of ASCII, and the numbers 0-128 have the same meaning in ASCII as they have in Unicode. For example, the number 65 mneans capital A". ASCII Unicode It uses 7 or 8 bits of byte space reserved for 1 It uses 2 Bytes as in Java so 65536 characters (2 bytes = it. Sometimes one last bit is used for another 16 bits, and the numbers 0 - 216) The text is encoded. significance. The latest version can cover almost 1 Lakh characters It is meant for English letters only Itcan be utilized for most of the languages in the world. 18. What are the escape sequences? List the known sequences with their functions. Ans. Some characters, if preceded by a backslash(), change their meaning and perform a specific function in Java known as escape sequences. Sayantan Mazumdar-Class X ICSE-Revision Chapter-SAQ Escape sequences are: Escape Sequences Non-graphic characters Escape Sequences Non-graphic characters \a- audible bell \v Vertical tab \b backspace \t Horizontal tab Single quote \n new line \' \r \f form feed Carriage return \” Double quotes \\ backslash 19. What is a token? Ans. A token is the smallest unit which depicts the smallest part of a program. 20. Write the memory capacity (storage size) of short and float data type in bytes. Ans. size of short data type = 2 Bytes size of float data type = 4 Bytes 21. What does the token ‘keyword’ refer to, in the context of Java? Give an example of keyword. [2011,2016] Ans. Keyword is a reserved word in Java which has its special meaning. A keyword can t be used as an identifier in the program. main(), int, if, for are some examples of Java keywords 22. Name the keyword which: (i) indicates that a method has no return type (ii) makes the variable as a class variable. Ans. (i) void keyword indicates that the method has no return type (ii) static keyword makes the variable as a class variable 23. What are the identifiers? Ans. The names of variables, classes, objects, functions(or methods), array, etc are given by programmers and they are called as identifiers. 24. What is a literal? Ans. A constant value is called a literal. It gives the exact representation of the data. For example, 11, 29.7, ‘p’, “pincode”. 25. What are variables? Ans. A memory location that stores a value is identified by a variable name. This stored value may change during the execution of the program and thus the name vary Table. 26. What do you mean by ‘data type’ of a variable? Ans. Data type refers to the type of value to be stored in a variable or the type of value to be used for calculations and other manipulations in the expressions. 27. Write the size of the following integer data types, both in terms of bytes and bits. (A) int (B) short (C) long (D) byte Or Write the memory capacity (storage size) of short and float data type in bytes. Data type Storage space (in bytes) Storage space (in bits) (A) int 4 32 (B) short 2 16 (C) long 8 64 (D) byte 1 8 Sayantan Mazumdar-Class X ICSE-Revision Chapter-SAQ 28. Write the range of acceptable values of these data types: (a) int (b) short (c) long (d) byte Ans. (a) int:-231 to 231-1 (b) short:-32768 to 32767 (c) long:-263 to 263-l (d) byte:-128 to+127 (signed) 29. Write the range of acceptable values of: (a) float (b) double -38 38 Ans. (a) float: 3.4 x 1O to 3.4 x 10 -308 307 (b) double: 1.7 x 1O to 1.7 X 1O 30. Differentiate between Primitive data types and Non-Primitive Data Types. Primitive Data Types Non-Primitive Data Types Independent data types. Dependent on primitive data types. It has predefined types of data. User has to define, before using them. It holds actual value. It holds address of the value. It has fixed memory. Its memory varies. For example byte,int,long,double etc. For example array, classes interfaces etc. 31. What is typecasting. Write an example of each kind of typecasting. OR Explain the term type casting. Ans. Typecasting is a process of data type conversion when a variable of one data type is assigned to another. Example of implicit typecasting: When a character is stored in an integer variable. int x= 'A' System.out.print (x); Output : 65 Example of explicit typecasting: When an integer is assigned to a character variable int x = 97; char m = (char) x; System.out.print (m); Output : a 32. (a) Which type of type-casting are shown in the following examples? (i) double x = 15.2; int y = (int)x; (ii) int x = 12; long y = x; (B) State the difference between a boolean literal and a character literal. Ans. (A) (i) Explicit typecasting (ii) Implicit typecasting (B) Boolean literals are true and false. A boolean literals are only stored in a variable whose data type is boolean. boolean A character literal is any character enclosed within single quotes. It can be stored in a variable whose dadata type is char. Sayantan Mazumdar-Class X ICSE-Revision Chapter-SAQ Examples : boolean x = true; boolean literal character literal 33. What do you mean by operands and operators? Ans. Operands are the quantity that are manipulated and operators are the symbols that represent precise operation. For example, in the expression y/3;y and 3 are operands and / is an operator. 34. What is unary’ operator? Discuss various unary operators used in java. Ans. Unary operators: Operators that deals with only one operand (a single variable or a literal for arithmetic unary operator and a single relational expression for a unary logical operator) is known as unary operator. Some of the unary operators used in Java are listed below: Logical NOT operator (!):Performs logical negation on an expression. Increment Operator(+ +): It is used to increase the value of variable by 1. Decrement Operator(- -): It is used to decrease the value of variable by 1. Increment and decrement operators are further classified into two types: Post fix operator- “change after the action”_ p+ +, p- -: Pre fix operator- “change before use”_ + +p, - - p; 35. What are the binary operators? Ans. The operators that take two operands to perform an operation are called as binary operators. Operators like (+, - *, /. %) are called as binary arithmetic operators. Operators like (, = =, =,! =) are called as relational operators. Operators like (&&, | |) are called as binary logical operators. 36. What is ternary operators? Explain the ternary operator used in java language. Ans. Operators that deal with three operands are called as ternary operator. The conditional operator(?:) is a ternary operator used in Java. String fare — (age= (greater than or equal to) (iv) ++ (increment) Ans: In other words, the increment operator (++) has the highest precedence, followed by the modulo operaoperator (%), the greater than or equal to operator (>=), and the logical AND operator (&&). Sayantan Mazumdar-Class X ICSE-Revision Chapter-SAQ 39. Write down java expression for: T=vA'+ B+ C Ans. double T = Math.sqrt(A*A+B*B+C*C); 40. Identify the literals listed below: (i) 0.5 (ii) A' (iii) false Ans. (i) Floating literal (üi) Character literal (üü) Boolean literal 41. If int y=10 then find int z = (++y *(y++ +5)); Ans. 176 42. What are the values of x and y when the following statements are executed? int a= 63; b=36; boolean x=(a>b)? true:false; int y= (a0)?1:-1):0; (d) grade=(!(percent>90)2(percent>70)?B:C;:A; (c) System.out.print(m==0)?"Hello":*Good Day"); 51. (a) What is the use and syntax of a ternary operator? (b) Rewrite the given expression: (r>0)? a=0): (6=0) using if-else statement; (c) Rewrite the following program segment using if-clse statements instead of the ternary operator. String grade= (mark>=90) ? A": (mark>=80) ? “B" :"C"; (d) State the values of n and ch. char c='A'; int n=+1; char ch=(char)n; Ans. (a) Syntax of ternary operator : Condition? expression to be evaluated when condition is true (:) expression to be evaluated when condition is false. Use: It can be used in place of an ifelse statement to make decisions and then to evaluate the expressions selectively. (b) if(>0) a=0; else b=0; (c) The program is as follows: if(mark> =90) grade=A"; else if(mark>=80) grade = "B" clse grade= "C"; (d) n = 66 ch= B

Use Quizgecko on...
Browser
Browser