Class As A User Define
Class As A User Define
(a) Find the access specifier which prohibits a class member from being used outside a class:
1. Private
2. Public
3. Protected
4. None of these
(b) Which of the following keywords are used to control access to a class member?
1. Default
2. Abstraction
3. Protected
4. Interface
(e) Which keyword makes class members accessible outside the class in which they are declared?
1. Private
2. Protected
3. Public
4. Hidden
f) Find the access specifier which prohibits a class member from being used outside a class:
1. Private
2. Public
3. Protected
4. None
h) Which of the following statements is the most appropriate for the private members?
1. They are visible out of the class in which they are defined.
2. They can be used in the sub-classes.
3. They are only visible in the class in which they are declared.
4. None of the above.
i) Which of the following keywords are used to control access to a class member?
1. Default
2. Abstraction
3. Protected
4. Interface
j) Which of the members can be accessed globally?
1. private
2. public
3. protected
4. All of the above
l) A class contains:
1. Attributes and methods
2. A number of object of same types
3. Data and member function
4. All of the above
n) A package is a:
1. collection of data.
2. collection of functions.
3. collection of classes.
4. a nested class.
o) Consider the following code and answer the questions that follow:
class academic
{
intx,y;
void access( )
{
inta,b;
academic student=new academic( );
System.out.println("Object Created");
}
}
(i) What is the object name of the class?
1. academic
2. student
3. access
4. None of these
(ii) Name the instance variables used in the class.
1. x, y
2. a, b
3. both of the above
4. none of these
(iii) Write the name of local variables used in the program.
1. x, y
2. a, b
3. both of the above
4. none of these
p) What should be the execution order, if a class has a method, static block, instance block, and constructor, as
shown below?
public class First_C {
public void myMethod()
{
System.out.println("Method");
}
{
System.out.println(" Instance Block");
}
public void First_C()
{
System.out.println("Constructor ");
}
static
{
System.out.println("static block");
}
public static void main(String[] args)
{
First_C c = new First_C();
c.First_C();
c.myMethod();
}
}
1. Instance block, method, static block, and constructor
2. Method, constructor, instance block, and static block
3. Static block, method, instance block, and constructor
4. Static block, instance block, constructor, and method
Up to ₹2,50,000 No tax
void input() Stores the cost of the article and name of the customer
void display() Displays the name of the customer, cost, discount and amount to be paid
Write a program to compute the discount according to the given conditions and display the output as per the
given format.
Up to ₹5,000 No discount
Output: