Get premium membership and access questions with answers, video lessons as well as revision papers.

By use of relevant examples, state the difference between i. Statement and a block. ii. Superclass and subclass iii. Function overloading and overriding

      

By use of relevant examples, state the difference between
i. Statement and a block.
ii. Superclass and subclass
iii. Function overloading and overriding

  

Answers


gregory
i. Statement and a block.
A statement forms a complete unit of execution e.g. System.out.println("Hello World!");
A block is a group of zero or more statements between balanced braces and can be used anywhere a single
statement is allowed. e.g.
if (condition) { // begin block 1
System.out.println("Condition is true.");
} // end block one
else { // begin block 2
System.out.println("Condition is false.");
} // end block 2
}
}
ii. Superclass and subclass
Inheritance is the process by which objects of one general class acquire the properties of objects of another
(derived) class. A derived class is a class defined by adding instance variables and methods to an existing
class. The existing class that the derived class is built upon is called the base class, or superclass. A base class
is also called a superclass, a parent class, and an ancestor class. A derived class is also called a subclass, a
child class, and a descendant class
iii. Function overloading and overriding
Overloading a method name means giving the same name to more than one method within a class. To do
this, you must ensure that the different method definitions have something different about their parameter
lists i.e. either have different numbers of parameters or have corresponding parameters with differing
types.
Overriding - In a derived class, if you include a method definition that has the same name, the exact
same number and types of parameters, and the same return type as a method already in the base class, this
new definition replaces the old definition of the method when objects of the derived class receive a call to
the method.
gregorymasila answered the question on January 24, 2018 at 17:33


Next: State and explain four advantages of Java as an object oriented programming language.
Previous: Explain the following terms: i. Inheritance ii. Encapsulation iii. Polymorphism

View More Computer Science Questions and Answers | Return to Questions Index


Learn High School English on YouTube

Related Questions