Introduction To Object Oriented Programming Concepts

1. What is an object?

Ans- i) Real world object – The object which having both characteristics and behaviour.

ii) Software object – The object which having both variables and related methods.

2. What is a class?

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

3. Write down the short notes on principle of object oriented programming language.

Ans- i) Abstraction :- Without getting involve to the entire system it repesents the essential features.

Ex:- While surfing on mobile phones we don’t get involve with entire system, we need to know only about essential features.

*Benefit :- The complex system ae layeed into moe manageable pieces.

ii) Inheritance :- An object acquire the properties of another object.

Ex:- {Grandfather}

|

{Father}

|

{Child}

In this example child having some quality of his grandfather.

iii) Polymorphism:- To represent a class in different ways is called polymorphism.

Ex:- To represent the score board of cricket, different types of chat like pie chart, column chart, bar chart, etc. are used.

iv) Encapsulation:- The wrapping up of data and methods into a single unit is called encapsulation.

Ex:- In a pen, if caps and refill all join together it will call a pen and it is used for writing.

Benefits:- (a) Modulaity:- The souce code of an object witten and maintained independently.

(b) Infomation hiding:- It means the infomation of an object cannot be passed by without pemission of an object.

4. What is the difference between class vs object?

Ans- Class

i) It does not lies on memoy.

ii) It is an abstact type.

Object

i) It lies on memoy.

ii) It is an instance type.

5. What is a method?

Ans- A method is a sub-program that acts on data and often return a value.

6. What is a data type?

Ans- The type of information stored in a variable is called data type.

Ex:- int a=3;

7. What is a variable?

Ans- A variable is a memory location in which data and information are stored.

8. What is a character set?

Ans- A character set consists of alphabets (small letters and capital letters), Digits code(0,1,2,……….9), special character ({ },[ ],/,*,etc.)

9. What is an escape sequence?

Ans- The non-gaphic o non-pintable chaactes ae called escape sequence.

11. What is a token?

Ans- The smallest unit of a java program that are used by the java compiler for constructing expression and statement is called token.

Ex:- int a=b+c;

12. Write down the types of token.

Ans- i) Reserved keyword

ii) Identifier

iii) Literal or constant

iv) Operator

v) Separator

13. What is a keyword?

Ans- Keywords are the reserved word which convey special meaning to the compiler.

Ex:- public, void, break, continue, etc.

14. What is an Identifier?

Ans- The symbolic name used for various data item is called Identifier. Ex:- S_name, e_name.

15. What are the rules to give a name to an Identifier?

Ans- i) It should not be start with a digit.

ii) Only underscore and dollar symbols are used.

iii) Spaces ae not allowed within an Identifien.

iv) It can be written in both upper case and lower case letters.

16. What is a Literal?

Ans- The data item which does not change its value during execution time.

Ex:- int a=5;

17. What is an operator?

Ans- An operator is a symbol which operates the operands.

Ex:- a=3+5

18. What is a separator?

Ans- Separators are the special symbols that help to define the stucture of a program.

Ex:- ( ), { }, ;, ,, ., etc.

19. What is a local variable?

Ans- The variable which ae declared inside of a function is called local variable.

Ex:- class Variable

{

public void work( )

{

datatype variable=value;

}

}

20. What is an instance variable?

Ans- The variable which is declared outside of a function but inside a class is called instance variable.

Ex:- class Vaiable

{

int a;

public void work( )

{

System.out.println(a);

}

}

21. What is a static variable?

Ans- The vaiable which ae declaed outside of a function but it must be explicitly declaed as a static.

Ex:- class Variable

{

static int a=5;

public void work( )

{

System.out.println(a);

}

}

22. What is the role of final keyword in java program?

Ans- Final keyword make a constant variable throughout a program.

Ex:- Final int a=5;

23. What do you mean by dynamic initialisation?

Ans- Dynamic initialisation means the variable are initialised during execution of a program. Ex:- int a=2;

24. What are the types of data type?

Ans- There are two types of data type:-

i) Primitive data type

ii) Non-primitive data type

25. What is a primitive data type?

Ans- The all fundamental data types of java are called primitive data type.

Ex:- int, long, shot, etc.

26. What is a composite or non-primitive data type?

Ans- The combination of primitive data types is called composite data type.

Ex:- class, aay, sting,etc.

27. What is the difference between primitive and non-primitive data type?

Ans- Primitive data type

i) It is an independent data type.

ii) Size is fixed.

iii) It is a fundamental data type.

Non-primitive data type

i) It is a dependent data type.

ii) Size is not fixed.

iii) It is an user defined data type.

28. What are the forms of operator?

Ans- There are three types of forms of opeator in Java:-

i) Unary operator

ii) Binary operator

iii) Ternary operator

29. Write down the short notes on forms of operator.

Ans- i) Unary operator :- The operator which required one operand to perform an operation is called unary operator.

Ex:- ++, –, ! P++, P–, –P, ++P.

ii) Binary operator :- The operator which require only two operands to perform an operation is called Binary operator.

Ex:- +, -, *, %, / a+b, a-b, a*b, a%b, a/b, etc.

iii) Ternary Operator :- The operator which require only thee operands.

Ex:- ?, : a=c=a>b?a:b; c=3

30. Write down the types of operator.

Ans- i) Aithmetic opeato:- (+, -, *, /, %)

ii) Relational opeator :- (>, <, <=, >=, !=)

iii) Logical operator:- (and &&, or ||, not !)

iv) Increment and decrement operator :- (++,–)

v) Short hand operator :- (conditional operator :?;)

31. What do you mean by precedence of opeator?

Ans- Precedence of operator means opeartor are operated according to priority basis in an expression.

32. What is a package?

Ans- A package is a collection of related classes.

33. What are the needs of a package?

Ans- i) Perventing naming conflicts

ii) Providing controlled access

35. Write down the name of pre-defined package.

Ans- i) java.lang

ii) java.io

iii) java.util

iv) java.applet

v) java.awt

vi) java.net

36. Write down the short notes on pre-defined package.

Ans- i) java.lang – This package supports the classes (primitive data types, math operations). It is also called a default package.

ii) java.io – It contains the classes for input output operations.

iii) java.util – It contains all the utility classes which implement the data structure like linked list, dictionary, scanner class and support date and time operations.

iv) java.applet – It contains the classes for creating applets.

v) java.awt – It contains the classes for implementing the components for graphical user interface like buttons, menus, etc.

vi) java.net – It contains the classes for supporting network operations.

37. Which keyword is used to include a package in a program?

Ans- import

Example : import java.io.*;

import java.util.*;

38. What is a user defined package?

Ans- The package which are defined by user is called user defined package.

39. Write down the name of method of scanner class which are used to input in Java.

Ans- i) Integer – ob.nextInt( );

ii) Float – ob.nextFloat( );

iii) Double – ob.nextDouble( );

iv) Character –

v) String

* For a word – ob.next( );

* For a sentence – ob.nextLine( );

40. Write down the name of methods of Buffered Reader class.

Ans- i) Integer – Integer.parseInt(ob.readLine( ));

ii) Float – Float.parseFloat(ob.readLine( ));

iii) Double – Double.parseDouble(ob.readLine( ));

iv) Character – (char)ob.read( );

v) String – ob.readLine( );

41. What is a system class?

Ans- The class which encapsulates several aspects of run time environment.

42. Write down the name of object and their function of system class.

Ans- i) in – It is used to input data. (connected with keyboad)

ii) out – It is used to display the output. (connected with output device like monitor, printer, etc.)

iii) error – It is used to display the error. (connected with output device)

44. Write down the syntax of all selection controlled statements in Java.

Ans- i) If

if(test condition)

{

//Statement;

}

ii) If-else

if(test condition)

{

//Statement1;

}

else

{

Statement2;

}

iii) If-else-if

if(test condition)

{

//Statement;

}

else if(test condition)

{

//Statement;

}

else

{

//Statement;

}

iv)Nested if

if(test condition)

{

if(test condition)

{

//Statement;

}

}

v)Switch case Statement

switch(expression)

{

case 1:Statement1;

break;

case 2:Statement2;

break;

.

.

case n:Statementn;

break;

default:Statement;

}

45. What is the role of default in a switch case statement?

Ans- If case value will not match, then the control automatically transfer to the default block.

Example:-

class Default

{

public void work(int n)

{

switch(n)

{

case 1:

System.out.println(“I am in case 1”);

break;

case 2:

System.out.println(“I am in case 2”);

break;

default:System.out.println(“Invalid option”);

}

}

}

46. Write down the type of case label used in a switch case (fall through) statement for an expression.

Ans- byte, short, int, char, long

47. What is a loop?

Ans- A loop is an itteration contolled statement which executes the statement number of times until a termination condition is met.

48. Write down the types of loop.

Ans- Basically, there ae two types of loop:-

i) Definite loop (Finite loop)

ii) Indefinite loop (Infinite loop)

49. What is a definite loop?

Ans- The loop which peforms up to given limit.

50. What is an indefinite loop?

Ans- The loop which peforms up to an infinite limit.

52. Give an example of indefinite loop.

Ans-i) fo(;;)

ii)while(true)

{

//Statement;

}

iii) do

{

//Statement;

}

while(true);

53. What is a jump statement?

Ans- The statement which interupt the normal flow of a progam.

54. Give an example of jump statement.

Ans- Break, Continue and Return.

55. What is a beak statement?

Ans- The statement which come out of the loop instantly is called a break statement.

Example:-

for(i=1;i<=5;i++)

{

if(i==3)

{

break;

}

else

{

System.out.println(i);

}

}

Output :- 1

2

56. What is a continue statement?

Ans- The statement which directly jump to the loop for the next iteration.

Example:-

for(i=1;i<=5;i++)

{

if(i==3)

{

continue;

}

else

{

System.out.println(i);

}

}

Output:- 1

2

4

5

57. What is a return statement?

Ans- The statement which usually used at the end of the function to terminate it with or without return the value.

Example:-

*public int work(int n)

{

return n;

}

*public int work(int a, int b)

{

c=a+b;

return c;

}

58. What do you mean by nested loop?

Ans- A loop within another loop is called nested loop.

Example:-

for(i=1;i<=5;i++)

{

for(j=1;j<=i;j++)

{

System.out.print(j);

}

System.out.print(i);

}

Output :- 1

1,2

1,2,3

1,2,3,4

1,2,3,4,5

59. Write down the syntax of nested loop.

Ans- for(initialisation;condition;rotation)

{

for(initialisation;condition;rotation)

{

//Statement;

}

}

Leave a Reply

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