Informatics Practices Class 12 Important Questions Chapter 5 GUI Programming and Access Specifier

Informatics Practices Class 12 Important Questions Chapter 5 GUI Programming and Access Specifier is part of Informatics Practices Class 12 Important Questions. Here we have given Informatics Practices Class 12 Important Questions Chapter 5 GUI Programming and Access Specifier.

Informatics Practices Class 12 Important Questions Chapter 5 GUI Programming and Access Specifier

1 Mark Questions

Question 1.
What will be the value of XI after execution of the following code? (Delhi 2014)

String X1 =‘‘Graduate”, X2 =“Post”;
X1 =X2.concat(Xl);

Answer:
Value of X1 will be “PostGraduate”.

Question 2.
The method is used to extract specified number of characters from a string.
(a) subStr( )
(b) substring( )
(c) C takeString( )
(d) extract( )
Answer:
(b) substring)

Question 3.
Which of the following method(s) does not accept any arguments?
(a) pow( )
(b) toLowerCase( )
(c) round( )
(d) All of the above
Answer:
(b) toLowerCase()

Question 4.
Which of the following statement is true?
(a) The trim( ) method is used to trim a string by removing white spaces from one side.
(b) The trim( ) method is used to trim a number by removing zeroes.
(c) The trim( ) method is used to trim a string by removing white spaces from both sides.
(d) The trim( ) method is used to trim a string by removing extra characters.
Answer:
(C) The trim() method is used to trim a string by removing white spaces from both sides.

Question 5.
Which of the following is not a valid method of the String class?
(a) length( )
(b) concat( )
(c) trim( )
(d) round( )
Answer:
(d) round()

Question 6.
is a class which contains methods for basic numerical operations like rounding off the number.
(a) Number
(b) String
(c) Math
(d) Integer
Answer:
(C) Math

Question 7.
What will be the effect of executing the following code?

String F1=“INTER".F2="MEDIATE”;
F1 = F1.concat(F2);

(a) F2 will be concatenated at the end of F1 and stored in F1
(b) F1 will be concatenated at the end of F2 and stored in F1
(c) F1 will be concatenated at the end of F2 and stored in F2
(d) F2 will be concatenated at the end of F1 and stored in F2
Answer:
(a) F2 will be concatenated at end of F1 and stored in F1,

Question 8.
What will be the contents of L after executing the following code?

String F1= “R”,F2; // represents a space F2=F1.trim( );
int L=F2.length( );

(a) 5
(b) 1
(c) 10
(d) 6
Answer:
(b) 1

Question 9.
Which of the following is not a primitive data type in Java?
(a) float
(b) int
(c) string
(d) void
Answer:
(c) string

Question 10.
What is the difference between equals() and equalsIgnoreCase() string methods?
Answer:
The equals() method compares two strings matching the cases of the strings. It means the uppercase and lowercase characters are treated differently while comparing the strings. Whereas the equalslgnoreCase() method compares two strings after ignoring the cases of the string. It means uppercase and lowercase letters are treated same.

Question 11.
What will be the contents of FI and F2 after the following code is executed?

String F1=“Hello”, F2=“Friends”; F1=F1.concat(F2);

Answer:
contents of F1 = HelloFriends contents of F2 = Friends

Question 12.
Through which operator the public members of a class can be accessed in the main method?
Answer:
The public members of a class can be accessed through the dot(.) operator.

Question 13.
What do you mean by StringBuffer class in Java?
Answer:
The StringBuffer class is an alternative to the String class. The length of buffer is referred as the capacity of buffer and it is not the same as length of the string. Whenever we need to change the length of the string in StringBuffer object, we can use the setLength() method.

Question 14.
In which class the pow() and round() methods are found?
Answer:
The pow() and round() methods in Java language are found in the Math class.

Question 15.
Name the three classes available in Java, to work with character data.
Answer:
The three classes available in Java to work with character data are as follows:

  • Character class
  • String class
  • StringBuffer class

Question 16.
What do you mean by library in Java?
Answer:
A library in Java refers to a set of readymade software routines (i.e. class definitions) which can be reused in the Java programs

Question 17.
What is the difference between capacity() and length() methods of a String class?
Answer:
The capacity() method returns the maximum number of characters that can be accommodated in a String object. Whereas the length() method returns the number of character of a string.

Question 18.
What is the use of toLowerCase() and toUpperCase() string methods in Java?
Answer:
The toLowerCase() string method converts all characters of a string into lowercase (i.e. small letters), whereas the toUpperCase() string method converts all characters of a string into uppercase (i.e. capital letters).

2 Marks Questions

Question 19.
Write the output: (All India 2014C)

System.out.println(Math.pow(4.0, 2.0));
System.out.printIn(Math.round(6.459));

Answer:
Output
16.0
6

Question 20.
Define object-oriented programming. (All India 2014)
Answer:
Object-Oriented Programming
Object-oriented programming is a programming paradigm in which the programs are organised in terms of objects rather than actions and more emphasis is given on data rather than logic. Because of this organisation object-oriented programming provides various features as:

  1. Data hiding A class defines the related data and when an instance of that class is run the code will not be able to accidentally access other program data.
  2. Reusability It provides reusability of code.
  3. User-defined data types Concept of classes allows programmers to define their own data types.

In this, the programming task is divided into objects. The methods are subroutines or procedures that are capable of performing the defined task. Object-oriented programming follows the bottom-up approach in program design and emphasises on safety and security of data.

Question 21.
Define data encapsulation with reference to object-oriented programming. (Delhi 2011)
Answer:
Process of wrapping up of data and methods in a single unit is known as encapsulation. In OOP data and associated methods are bound together to make a single unit i.e. class.

Data is not accessible to outside world and only class methods can get access to it. This insulation of data from direct access by the program is called as data hiding.

Question 22.
Define a class with reference to object-oriented programming. (All India 2014 C, 2011)
Answer:
A logical structure upon which the object is build, i.e. a class is a group of object that shares common properties and relationships. In other words, class is a collection of objects of similar types.
E.g., Car, Truck, Bike and Cycle are the members of class Vehicle.
Informatics Practices Class 12 Important Questions Chapter 5 GUI Programming and Access Specifier 1

Question 23.
Differentiate between call by value and call by reference.
Answer:
In call by value method, the actual parameters are copied into the formal parameters. A separate copy of arguments is created in the memory and then it would be used. If there is any modification in the formal variable inside the method. It will not be reflected to the original varibale.

Whereas under the call by reference, new copy is not created rather the original values are used. So, if there is any modification in the variables inside the method, it will be reflected to the original variables.

Question 24.
What are the formal and actual parameters of a method?
Answer:

The parameters which appear in method definition are known as formal parameters. The parameters that appear in method call statement are known as actual parameter. We can pass primitive data type values (like char, byte, short, int, long, float, double and boolean) or reference data type values (such as objects or arrays) to a method.
E.g.,

int peri (int x, int y)
//Formal parameters
{
int z=2*(x+y); 
return z;
}

The code from where the method is called could be as follows:

int 1ength = 5;
int breadth = 4;
i nt peri meter = peri(1ength,breadth); //actual parameters

Question 25.
What do you mean by a method? What is method prototype?
Answer:
Method The methods are used to specify some actions within a class. For performing an action through a method, a message can be sent to the respective method. A message to an object is call to the object’s method requesting that it performs some specified actions.
Method Prototype It is the definition of the method that defines the functioning of the method, i.e. what the method will do when it will be invoked.
The method must be defined before it is used in a program. .
The general form of method definition is as given below:

[access-specifier] [modifier]
return_type method_name (arguments)
{
.
.
.
//body of method;
.
.
.
}

Question 26.
How can we extract the behavior or properties of one class into another?
Answer:
To extract the properties of one class into another class, we use inheritance. It is the capability of one class to inherit capabilities or properties from another class. Whenever we have to reuse the properties and capabilities, we can inherit them into another class without rewriting the same.

Question 27.
What is the difference between a concrete and an abstract class?
Answer:
The classes for which objects are required to be declared are known as concrete classes like JLabel, JTextField, JComboBox, etc. The Classes for which it is not essential to declare objects to use them are known as abstract classes, objects can not be created. Abstract classes are normally used as base class in inheritance for which no direct object can be created. Also, abstract classes are used for defining generic methods, where there is no requirement of storing results.

Question 28.
Define inheritance with reference to object-oriented programming.
Answer:
Inheritance is the capability of one class of things to inherit capabilities or properties from another class. Whenever we have to reuse the properties and capabilities, we can inherit them into another class without rewriting the same. Inheritance is an important and powerful feature of object-oriented programming. The inheritance is a process of creating a new class (i.e. derived class, subclass or child class) from existing class (i.e. base class, superclass or parent class).

Question 29.
What is friendly access specifier?
Answer:
The default access specifier is friendly. It means, if we do not explicitly define any access specifier before a method, Java assumes the same a friend to all classes in the same package and it will be accessible in the classes of same package and in the subclasses of same package, but it will not be accessible in the subclasses of other packages and in the classes of other packages.

Question 30.
What do you mean by public access class members?
Answer:
A public class access specifier is a visibility mode which is used, when we need to access a method to be accessed from all other classes. It means when we declare a method as public, it can be accessed from all other classes. Any method declared as public can be accessed from anywhere, any package in the class and it will be accessible everywhere i.e. in the classes in the same package and in the subclasses of same package, in the subclasses of other packages and in the classes of other packages.

Question 31.
How are private members of a class are different from the public members of a class?
Answer:
A private class member has accessibility only within the class in which it has been declared. Private members cannot be accessed by the object of that class even. Whereas a public class member is accessible everywhere in the program. It means it will be accessible everywhere, i.e. in the classes of same package and in the subclasses of same package, in the subclasses of other packages and in the classes of other packages.

Question 32.
How are protected members different from public and private members of a class?
Answer:
The protected members of a class which are declared by using the protected keyword denotes a variable or method as being public to subclasses of this class but private to all other classes outside the current package. So, derived classes have the ability to access protected variable of its parent class. Whereas the private members of a class that are declared using the private keyword denotes a variable or method as being private to the class and cannot be accessed outside the class. Accessing will be done through calling one of the public class methods.

Question 33.
How can we hide the information of a class?
Answer:
To hide the information of a class, we have to use the private access specifier with the variable names and methods whom we want to hide. To declare a method as a private, we have to use the keyword private.

The private access specifier denotes a variable or method as being private to the class and may not be accessed outside the class. Accessing will be done through calling one of the public class methods. The private access specifier is the most restrictive access level. Such methods can be accessed only through the other member methods of same class.

Question 34.
Write a program in Java to read a text and count all occurrence of a particular text.
Answer:

String myStr = Textl.getText(); 
char ch = chart.getTextf).charAt(O); 
int c=0;
forfint i=0; i<myStr.1ength(); i++)
{
if(myStr.charAt(i) = = ch)
C++;
}
occurLabel1.setTextf" ” +c);

Question 35.
Write a program in java to read a text and reverse the input text, without using the reverse() library function.
Answer:

String str = jTextFieldl.getText(); 
String strl=“
forfint i=str.1engthf )-l;i>=0;i—)
{
strl = strl + str.charAt(i);
}
jTextField2.setText(strl);

Question 36.
Write a program in Java that accepts a text and count the number of vowels present in it.
Answer:

String myStr = Textl.getTextf); 
int c=0;
forfint i=0; i<myStr.1engthf); i++)
{
if (myStr.charAt(i) = = ‘a’ || 
myStr.charAt(i) = = ‘A’ || 
myStr.charAt(i) = = ‘e’ || 
myStr.charAt(i) = = ‘E’ || 
myStr.charAt(i) = = ‘i ’ || 
myStr.charAt(i) = = ‘ I ’ ||
myStr.charAt(i)== ‘o’ || 
myStr.charAt(i) = = ‘0’ || 
myStr.charAt(i) == ‘u’ || 
myStr.charAt(i) == ‘U’)
C++; .
}
occurLabel l.setText(" ”+c);

Question 37.
Briefly define the basic concepts of object-oriented programming.
Answer:
General concepts of object-oriented programming are as follows:

  1. Data Abstraction It refers to the act of representing essential features without including the background details or explanations. This is a concept of simplifying the real world into its essential elements. Here to access an option, we must know the method name.
  2. Data Encapsulation The wrapping up of data and operations/methods that operate on the data into a single unit called class is known as data encapsulation. Inside a class, we can keep both the data members and methods under a common unit.
  3. Inheritance It is the capability of one class of things to inherit capabilities or properties from another class. Whenever we have to reuse the properties and capabilities, we can inherit them into another class without rewriting the same.
  4. Polymorphism It is the ability for a data or a message to be processed in more than one form under different condition. It can be implemented in object-oriented programming through method overloading and method overriding.

We hope the Informatics Practices Class 12 Important Questions Chapter 5 GUI Programming and Access Specifier help you. If you have any query regarding Informatics Practices Class 12 Important Questions Chapter 5 GUI Programming and Access Specifier, drop a comment below and we will get back to you at the earliest.