Class as The Basis of All Computation

1. What is a class?

Ans- A class is a collection of similar type objects having same characteristic and behaviour.

2. What is a need of a class?

Ans- A class is needed to represent real world entities that not only have data type properties that is their characteristics but also associated operation that is their duty.

3. Write down the general form of a class.

Ans- <Access Specifier> <Class Name>

{

//Instance Variable1

//Instance Variable2

.

.

//Instance Variablen

Type of Method1( )

Type of Method2( )

.

.

Type of Methodn( )

}

4. Write down the syntax to create an object of a class.

Ans- <Class Name> <Object Name>=new<constructor>

6. What is a scope?

Ans- A scope is defined a block.

Example :- public void work( )

{

//Statement;

}

7. What do you mean by life time?

Ans- Life time means how many times the object is visible within that scope.

Example :- for(i=1;i<=n;i++)

8. What is the difference between local variable and global variable?

Ans- Local variable

i) When the variable is declared within the function.

Global variable

i) When the variable is declared outside the function.

10. Give an example of a class and instant variable.

Ans- class X

{

public void work(int a, int b) —> Impure

{

c=a+b;

System.out.println(c);

}

}

11. What is a method signature?

Ans- The header of a function is called method signature.

Example:- public int work( )

{

int a=3;

}

Leave a Reply

Your email address will not be published. Required fields are marked *