CH 3-4 Answers
CH 3-4 Answers
Section A
Q4. Differences:
(Examples)
a) Class is a template; Object is an instance of a class.
b) Primitive stores actual value; Non-primitive stores references.
c) Integer: 5, -10; Float: 3.14, -2.0f
d) Implicit is automatic; Explicit is manual casting
Q5. Outputs:
a) 20
b) true
c) 8
Q6. MCQs:
i) B. Sun Microsystems
ii) D. String
iii) C. &&
iv) B. 2 bytes
v) C. integer
vi) C. x = 5;
Section B
Q7.
a) OOP is a programming style that revolves around objects and classes.
b) Inheritance, Encapsulation, Abstraction, Polymorphism
c) Object: runtime entity; Class: blueprint; Method: function inside class
Q8.
a) A literal is a constant value written directly, like 5, 'A', "Hello"
b)
class Info {
public static void main(String[] args) {
String name = "Riya";
int age = 14;
System.out.println("Name: " + name);
System.out.println("Age: " + age);
}
}
c) x += 2; adds 2 to x
Q9.
a) byte, short, int, long, float, double, char, boolean with examples
b)
double d = 5.6;
int x = (int) d;
c) float pi = 3.14f;
Q10.
a) = is assignment; == is comparison
b)
Q11.
a) ++a increases before use; a++ after use
b) *, +, ==, && (correct order)
c) 2 + 6 - 1 = 7
Q12.
a) Java bytecode runs on any system with JVM
b)
int a = 10, b = 2;
System.out.println(a + b);
System.out.println(a - b);
System.out.println(a * b);
System.out.println(a / b);
System.out.println(a % b);