********EXPLAIN CLEARLY************ List the 3 main design principles of Object-
ID: 3822203 • Letter: #
Question
********EXPLAIN CLEARLY************
List the 3 main design principles of Object-Oriented Programming:
List the 4 primary programming logic constructs.
List the 3 parts of an iterative structure.
Name the 3 types of errors.
Explain overriding.
Explain overloading.
Explain casting.
Explain the keyword ‘throws’
Explain the keyword ‘extends’
Explain the keyword ‘void’
Explain the keyword ‘static’
List the 3 elements of a Java class definition:
12.Assume the following Java declaration statement:
int [][] matrix = {{2,4,6,8,10,12},{3,6,9,12,15,18},{1,2,3,4,5,6}};
What is the value of matrix.length?
What is the value of matrix[2].length?
What is displayed by the following Java statement?
for (int i = 0; i < matrix.length; i++)
System.out.print( matrix[i][0] + “ “ );
Write the code segment to find the sum of the entire matrix. Use sum, I and j
Consider the following method definitions:
public static void main(String[] args){
int count = 3;
printString(“Java”, count);
}
public static void printString(String message, int number){
for (int i = 0; i < number; i+) System.out.println(message);
}
What are the names of the formal parameters for method printString?
What is the signature of method printString?
What are the arguments for method printString?
How many times is the printString method invoked?
What output is produced when main is executed?
Write a method called Dash which will have the formal parameters of a character and an integer that will print a dash of type chat integer length. The signature would look like this:
Dash(‘*’,5);
Would result in a dash like this: *****
Use the following segment of Java code to answer the questions:
public class Employee {
private String firstName;
private String lastName;
private java.util.Date hireDate;
public Employee(){...}
public String getfirstName() {…}
public String getlastName() {…}
public String getdateHired() {…}
public void setLastName(String l){...}
public void setFirstName(String f){...}
public void setName(String f, String l){...}
public void print(){...}
public String toString() {….}
}
public class SalariedEmployee extends Employee{
private String title;
private double yearlySalary;
public SalariedEmployee(){...}
public void setSalEmp(String f, String l){...}
public void setSalEmp(String f, String l, double s){...}
public void print(){...}
public String toString () {…..}
}
What object-oriented programming principle is demonstrated by line 1?
What object-oriented programming principle is demonstrated by line 15?
In this example, which class is considered the subclass?
Give the name of the overloaded method(s) in this example.
Give the name of the overridden method(s) in this example.
List the attributes of a SalariedEmployee object:
Write the code that would create an array of 100 SalariedEmployees
Write a void static method called LastName_Salary which will list only the last name and the tabbed yearly salary of each employee.
Explanation / Answer
There are five principles of class design (aka SOLID):
When expanded the acronyms might seem complicated, but they are pretty simple to grasp.
Single-responsiblity principle:
A class should have one and only one reason to change, meaning that a class should have only one job.
Open-closed principle:
Objects or entities should be open for extension, but closed for modification.
Liskov substitution principle:
Let q(x) be a property provable about objects of x of type T. Then q(y) should be provable for objects y of type S where S is a subtype of T.
All this is stating is that every subclass/derived class should be substitutable for their base/parent class.
Interface segregation principle:
A client should never be forced to implement an interface that it doesn’t use or clients shouldn’t be forced to depend on methods they do not use.
Dependency Inversion Principle:
Entities must depend on abstractions not on concretions. It states that the high level module must not depend on the low level module, but they should depend on abstractions.
There are three principles of package cohesion
There are three principles of package coupling
Other OoDesignPrinciples:
programming logic constructs:
The three logical constructs that are used in all programming languages are sequence, selection (IF . . .THEN . . . ELSE and the case structure), and iteration or looping. These constructs can also be described as:
In this case, “selection” and “condition” are basically used interchangeably, as are “iteration/looping” and “repetition”
Types of error:
There are three types of error: syntax errors, logical errors and run-time errors. (Logical errors are also called semantic errors).
syntax errors:
a syntax error is an error in the syntaxof a sequence of characters or tokens that is intended to be written in a particular programming language. For compiled languages, syntax errors are detected at compile-time. A program will not compile until all syntax errors are correcte.
logical errors:
a logic error is a bug in a program that causes it to operate incorrectly, but not to terminate abnormally (or crash). A logic error produces unintended or undesired output or other behavior, although it may not immediately be recognized as such.
run-time errors. :
A runtime error is a program error that occurs while the program is running. The term is often used in contrast to other types of program errors, such as syntax errors and compile time errors. There are many different types of runtime errors. One example is a logic error, which produces the wrong .
overloading:
Overloading refers to the ability to use a single identifier to define multiple methods of a class that differ in their input and output parameters. Overloaded methods are generally used when they conceptually execute the same task but with a slightly different set of parameters.
Overloading is a concept used to avoid redundant code where the same method name is used multiple times but with a different set of parameters. The actual method that gets called during runtime is resolved at compile time, thus avoiding runtime errors. Overloading provides code clarity, eliminates complexity, and enhances runtime performance.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.