Kunal Java Unit-1
Kunal Java Unit-1
7. What are the keywords in java? Explain final this and static keyword.
1. Write down the basic concept of object oriented programming.
ANS-
1. Objects:
• Objects represent real-world entities and consist of both data (attributes/properties) and
behaviors (methods/functions).
2. Classes:
• Classes serve as blueprints or templates for creating objects. They define the structure
and behavior of objects.
3. Encapsulation:
• Encapsulation protects the valuable items (data) by hiding them within the chest and only
allowing access through the designated keys (methods), ensuring security and integrity.
4. Abstraction:
• Abstraction focuses on hiding complex implementation details and showing only the
necessary features of an object. It allows the creation of simpler and more manageable
models.
5. Inheritance:
6. Polymorphism:
• polymorphism allows different objects to be treated as the same type, enabling flexibility
and uniform interaction with methods or functions.
2. Difference bw oop and pop.
ANS-
Data Protection Data can be accessed freely Data is protected within objects
ANS-
1. Selection Statements:
System.out.println("Adult");
• switch Statement: Selects one of many code blocks to execute based on a variable’s value.
For example:
switch (day) {
// other cases
2. Iteration Statements:
• while Loop: Repeats a block of code while a condition is true. For example:
while (i < 5) {
System.out.println(i);
i++;
• do-while Loop: Similar to while, but the code block is executed at least once. For example:
do {
System.out.println(i);
i++;
System.out.println(i);
ANS-
1. Classes:
• Definition: A class is a blueprint for creating objects. It defines attributes (fields) and
methods (functions) that objects created from the class can use. For example:
String name;
int age;
void greet() {
2. Objects:
• Definition: An object is an instance of a class. It contains actual values and can use the
methods defined in the class. For example:
p.name = "Alice";
p.age = 30;
p.greet();
5. How to read console input in Java?
ANS- For it we use scanner classes and follows the following structure in our source
programme:
Source programme:
import java.util.Scanner;
}
6. What is constructor overloading?
ANS-
Rectangle() {
length = 1;
width = 1;
Rectangle(int l, int w) {
length = l;
width = w;
}
7. What are the keywords in java? Explain final this and static keyword.
ANS- In Java, keywords are reserved words that have specific meanings and purposes within
the language. They cannot be used as identifiers (e.g., variable names, function names) in your
code.
Final
It's used to create things that can't be altered after they're made.
• Final variable: A value that can't be changed once it's set. It's like a constant.
This
this.color = color; // Using 'this' to assign the parameter to the instance variable
Static
Imagine a shared room. Everyone can access things in the room without owning the room.
That's static. It belongs to the class itself, not to specific objects.
• Static variable: A variable that belongs to the class, not an object. All objects share the
same value.