Give answers for the following:
Attachments:
Answers
Answered by
4
Hey
Here you go
1)OOP
⭕ OOP is programming methodology in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.
⭕ A class is simply a representation of a type of object. It is the blueprint/ plan/ template that describe the details of an object(Class categorise the things up).
⭕Object is termed as an instance of a class, and it has its own state, behavior and identity.
Language that use OOP are
Java , C++, Python, Kotlin
2) A class is called an object factory because objects are created from a class. An object is an instance of a class.
The following statements create two objects s1 and s2 of the class Student.
Student s1 = new Student();
Student s2 = new Student();
So, we have a single class Student but we can create as many objects as we want (like s1, s2 etc.) from that single class.
This is similar to what happens in a factory. Consider a factory which produces car. They have only a single design of a car but produce multiple cars from that single design.
Things are similar in the world of classes and objects. There is a single definition of a particular class (like Student) but we can produce many Student objects (like s1, s2) from that single class.
3) Import is a keyword. import keyword is used to import built-in and user-defined packages into your java source file so that your class can refer to a class that is in another package by directly using its name.
Use the '*' character to declare all the classes belonging to the package.
⭕ Build-in package/class import
Syntax:
import package.JavaClass;
import package.*;
⭕ User define package/class import
Example :
Here, a class named Manager is added to the payroll package that already contains Employee. The Manager can then refer to the Employee class without using the payroll.
package payroll;
public class Manager
{
public void payEmployee(Employee e)
{
e.mailCheck();
}
}
4) Default statement us used to prevent error i.e.
if the given input is not found in switch case then it can use default statement as escape.
Suppose the input n in swtich statement is 4 then if we don't include default in it compiler has no place to go so that's why we use default case in switch.
switch(n) {
case 1:
A = 1;
break;
case 2:
A = 2;
break;
default:
A = 0;
}
5) It is must to use break after everystatement in switch
because the control flow goes to next statement or next case if we don't use it and if case 1: is choosen and we don't incluse break in it case 1: to case last and default as well will be executed
switch(n) {
case 1:
A = 1;
break;
case 2:
A = 2;
break;
default:
A = 0;
}
Hope this helps
Peace out!
Here you go
1)OOP
⭕ OOP is programming methodology in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.
⭕ A class is simply a representation of a type of object. It is the blueprint/ plan/ template that describe the details of an object(Class categorise the things up).
⭕Object is termed as an instance of a class, and it has its own state, behavior and identity.
Language that use OOP are
Java , C++, Python, Kotlin
2) A class is called an object factory because objects are created from a class. An object is an instance of a class.
The following statements create two objects s1 and s2 of the class Student.
Student s1 = new Student();
Student s2 = new Student();
So, we have a single class Student but we can create as many objects as we want (like s1, s2 etc.) from that single class.
This is similar to what happens in a factory. Consider a factory which produces car. They have only a single design of a car but produce multiple cars from that single design.
Things are similar in the world of classes and objects. There is a single definition of a particular class (like Student) but we can produce many Student objects (like s1, s2) from that single class.
3) Import is a keyword. import keyword is used to import built-in and user-defined packages into your java source file so that your class can refer to a class that is in another package by directly using its name.
Use the '*' character to declare all the classes belonging to the package.
⭕ Build-in package/class import
Syntax:
import package.JavaClass;
import package.*;
⭕ User define package/class import
Example :
Here, a class named Manager is added to the payroll package that already contains Employee. The Manager can then refer to the Employee class without using the payroll.
package payroll;
public class Manager
{
public void payEmployee(Employee e)
{
e.mailCheck();
}
}
4) Default statement us used to prevent error i.e.
if the given input is not found in switch case then it can use default statement as escape.
Suppose the input n in swtich statement is 4 then if we don't include default in it compiler has no place to go so that's why we use default case in switch.
switch(n) {
case 1:
A = 1;
break;
case 2:
A = 2;
break;
default:
A = 0;
}
5) It is must to use break after everystatement in switch
because the control flow goes to next statement or next case if we don't use it and if case 1: is choosen and we don't incluse break in it case 1: to case last and default as well will be executed
switch(n) {
case 1:
A = 1;
break;
case 2:
A = 2;
break;
default:
A = 0;
}
Hope this helps
Peace out!
Similar questions