السلام عليكم و رحمة الله و بركاته
Alsalamo alikom wa rahmato allahe wa barakato ,
After finishing my 8th chapter in “OOP demystified ” book , i wrote some questions and answers to them from my point of view , i listed some of them below :-
What is abstract object and real object ?
Abstract object is the object – the details , like the class is an abstract object but the object itself is a real object , that is because the real object actually holds data , not just say that it exsits …
Why we need to declare the type of our variables ?
We need that for two main purposes :-
- The computer need to know how much space to allocate for that variable ..
- The computer uses this piece of information to determine what operations to be performed on that variable , like integer variable can’t be transformed to uppercase , or string variables can’t be summed ..
What is the diffrence between instance variable and just variable ?
Instance variables are variables of the class , so it is not allocated for untill his object is instantiated , but normal variables are allocated for when the compiler reach them ..
What is initialzation and instantiation ?
Initialization is the process of setting a variable value , like name = “Adham”; , but instantiation is the process of determining the type of the variable so the computer can allocate memory for it , like String name; here you order the computer to allocate memory for a variable called name of type String .
What is Encapsulation ?
It is the process of combining the procedure and the attributes in one block called the object .
Why to use Encapsulation ?
We may use it to some organizational reasons ( just groupping related data and behaviours togather ) , but the main purpose of it is Protection , accepting only proper data , for instance this is a PHP function to register a new student in a course :-
function register_student($student_id,$course_id){
// do the registration
}
Any two parameters are accepted here even if they are not a student’s data !! , but using Encapsulation , you combine attributes and behaviours into an object so you can prevent non-student objects from registering themselves allowing only student objects …
Why we make setters and getters for private or protected properties ?
For setters we can use them to validate the new values , for getters we may use them for outputting on a specific manner like :-
class Student {
private status ;
public void setStatus(int status){
this.status = 1;
if(status == 0){
this.status = 0;
}
}
public Stirng getStatus(){
if(this.status == 0){
return “Success”;
}
return “Fail”;
}
}
What is Encapsulation ?
It is the process of combining the procedure and the attributes in one block called the object .
What are the types of Inheritance ?
Inheritance has three types :-
- Simple inheritance : class SubClass extends SuperClass ;
- Multiple inheritance : not supported in java , but it is simulated usnig interfaces .
- Level inheritance : when class a is a b is a c .
What are the differences between function and functionality ?
If we have a class represents a dog and another a human , both have common Function which is walking , but they have a different Functionality which is how they do the common function , for instance a human walks on two legs but the dog on four , so Function is something we do but Functionality is how do we do this Function .
Can any class implement some not all interface methods ?
If a class is abstract it can implemet an interface and don’t define all of its methods , But if this abstract class was subclassed , the sub class must implement the remaining methods because the subclass in fact implements this interface .
What are the common mistakes concerned with abstraction ?
There are three common errors concerned with abstraction :-
- Trying to instantiate an abstract class .
- Trying to call an abstract method from the super class .
- Forgetting to define an abstract metod in the subclass .
ISA i will post here regularly about Java from now on !!


thx Adham, keep it up
thanks for this kind reply .. correct my information ..