Ch1 4 Theory

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Q1. Define a class.

Ans. A class is a blueprint that defines the different attributes and common
behaviours that an object will contain. It is also known as an object factory. For
example class animal has objects cat and dog.
Q2. Define an object.
Ans. An object is a real world entity which contains the attributes and behaviours
defined by the class. An object is also known as an instance of a class. For example
objects cat and dog belong to class animal.
Q3. Differentiate between a class and object.
Ans.
Q4. How are class and object interrelated?
Ans. A class defines the attributes and behaviorsto be contained by an object and an
object contains the attributes and behaviors defined with the glass therefore they
both are interrelated.
Q5. How do we represent a real-world object as a software object?
Ans. As a software object, the attributes are represented through data members and
the behaviour are represented through member functions of a class.
Q6. State 4 attributes and three behaviours of:
a. Table d. Student
b. Flower e. Animal
c. School f. Employee
Q7. Define state, attribute and identity of an object.
Ans. State: the state of an object is represented by the values that are contained by
its attributes. The state of any two objects are generally different.
Attribute:The attributes of an object represents the features or the data members of
that object.
Identity: Identity of an object represents the name by which it is called. No two
objects can have same identity.
Q8. Class known as an object factory. Explain.
Ans. A class produces many objects of similar types. A class is called an object factory
because objects are created from the class that contains attributes and common behaviour.
The class behaves like a specification for creating such similar objects. Eg. Class Animal can
create objects Dog, Cat etc.
Q9. Class is a composite data type. Explain.
Ans. A datatype is used to declare variables, similarly a class is used to declare objects. A
composite data type is one which is composed with various primitive data type. A class is
defined with various primitive data types such as int, double etc; as its data members. Thus,
it is known as a composite data.
Eg. Class Student may contain roll_number as int, name as String and marks as double.
Q10. Class is a user defined datatype. Explain.
Ans. A datatype is used to declare variables, similarly a class is used to declare objects. A
class is known as a user defined datatype as its specifications (attributes and behaviour) can
be created as per the user’s need using the various inbuilt datatypes.
Eg. Class Student may contain roll_number as int, name as String and marks as double.
Q11. Object is known as an instance of a class. Why?
Ans. A class can create objects of itself with different characteristics (instance variables) and
common behaviour (member methods). So, we can say that an Object represents a specific
state of the class. For these reasons, an Object is called an Instance of a Class.
Q12. Explain all the principles of Java.
Ans.
1)Abstraction – Abstraction is an act of showing essential details and hiding the
background details. example camera
2) Encapsulation – Encapsulation is an act of wrapping up of data and functions into
a single unit. Example class
3) Inheritance – The process of sharing or linking the properties of one class with
another class is known as inheritance. The class whose properties are shared is
known as superclass, base class or parent class whereas the class who shares the
property is known as subclass, derived class or child class. it helps in achieving the
property of reusability.
4) Polymorphism – The process of using one function name for more than one
purpose is known as polymorphism. It is implemented through function overloading
in Java.
Q13. Which principle achieves the property of reusability and how?
Ans. Inheritance as in achieving reusability as the features are defined in the base
class once can be reused again by inheriting it in many subclasses.
Q14. How is encapsulation and abstraction interrelated?
Ans. define both encapsulation and abstraction in it
Q15. Define:
a. new Dynamic memory allocation
b. import Includes packages in the program
c. dot operator Sub membership operator used for accessing the members of a
class or a package
d. coercion Implicit typecasting
e. void return type denoting that the function will not return any value
f. Applets Small Java programs included in the web page and require web
browser and Internet to run
Q16. What do you understand by language processor?
Ans. Explain compiler and interpreter
Q17. State any 4 features of java which are not features of OOPs
Ans.
• Platform independent/ Architectural neutral
• Multithreading
• Distributed
• Both compiled and interpreted
Q18. Explain JVM.
Ans. JVM stands for Java virtual machine. It takes byte code as input and interprets
(using interpreter) it into a machine specific code. JVM has the capability of
converting any non Java bytecode into machine code.
19. Define Bytecode.
Ans. Byte code is an intermediate binary code generated by the Java compiler. It is a
platform independent code. It acts as an input for the JVM which translates it into a
machine specific code.
Q20. Difference between compiler and interpreter.
Q21. What are comments? Give syntax of each type of comment.
Ans. Comments are non executable statements included in the program to explain
the logic of the program they are used for documentation purposes. There are three
types of comments
Singleline comment //
Multiline comment /*….*/
Documentation comment /**….*/
Q22. What is a package? Name the default package.
Ans. A package is a collection of related classes. It is created using the keyword
package. It is included using the the keyword import.
The default package is java.lang
Q23. What are keywords?
Ans. Keywords are the words which have a special meaning or predefined meaning
to the Java compiler. for example public, import, void, CONST, gobyeto etc.
Q24. Differentiate between OOP &POP.
Q25. Differentiate between ASCII & Unicode.
Q26. Token?
Ans. Each individual component or building blocks of a Java program is known as a
token. For example public, { etc.
Q27. What are identifiers? Rules for valid identifier.
Q28. What are literals? How are they different from identifiers?
Q29. List all types of literals.
Q30. Differentiate between primitive and non-primitive data types.
Q31. State the size and default value of:
a) int b) double c) long d) byte e) char f) float
g) short h) boolean
Q32. What is an escape sequence?
Q33. What is type casting? Give example of both types.
Q34. What is the other name given to implicit type casting?
Q35. Differentiate between static and dynamic initialisation.
Q36. What is an operator?
Ans. Operator is a symbol used to perform a specific task. There are 3 types of operators,
namely, unary, binary and ternary operators. Eg. +, -, < etc.
Q37. Differentiate between unary and binary operators.
Ans. unary operator are the one which work only with a single operand. For example,
!, ++, --
Binary operators are the ones which word with 2 operands.for example +,-,*
Q38. Explain logical operators.
Ans. Logical operators are used for combining two or more conditions. They always
result in a boolean value,i.e., true or false.There are three logical operators &&, ||, !.
Q39. Define Ternary operator.
Ans. Ternary operators works with 3 operands. They are also known as conditional
operators and are used in place of if else statement. For example, g=(5>7)?7:5;
Q40. Differentiate between relational and logical operators.
Q41. Differentiate between = & ==
Q42. Differentiate between && and ||
Q43. Arrange the following in descending order of their preceedene: <,
==, =, (), ++, *, &&, +, %
Q44. Identify the invalid identifier:
_a1, string, java, 2a, public, Main
Q45. Declare the variables with appropriate data types and store the following given
values in them:
184.57, 18256789, @, 1-141-242-342, false
Q46. State the output of:
a) System.out.println(“Welcome\n” + “to\n” + “\“Computer\”” + “\t” + “world”);
b) class PrePostDemo
{
public static void main(String[] args)
{
int i = 3;
i++;
System.out.println(i);
++i;
System.out.println(i);
System.out.println(++i);
System.out.println(i++);
System.out.println(i);
}
}
Q47. Evaluate:
a) int i = 10; int n = i++%5;
What are the values of i and n after the code is executed?
i = --x y++ - z-- - --z + ++y - --x + y-- - --x,
where i=10, x=8, y=5, z=6
All questions from file shared
Q48. Write the java expression:
All questions from file shared
Q49. Define a class Student having 3 attributes and 2 behaviours.
Q50. Create an object dzire of class Honda.
Q51. Explain dual utility of Java.
Q52. Java is both compiled and interpreted. Explain.

You might also like