The following program contains 3 files.   1) absWelcome.java   public abstract class absWelcome {   // abstract method :   public abstract void printMessage();   // regular method :   public void printWelcome() {    System.out.println("Welcome to");   } }   2) clsHello.java   public class clsHello extends absWelcome {   // overriding the abstract method :   public void printMessage() {    System.out.println("Java Programming");   } }   3) Main.java public class Main {  public static void main(String[] args) {   // object creation :   clsHello obj = new clsHello();   // using object to call methods :   obj.printWelcome();   obj.printMessage();  } }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

The following program contains 3 files.

 

1) absWelcome.java

 

public abstract class absWelcome {
  // abstract method :
  public abstract void printMessage();
  // regular method :
  public void printWelcome() {
   System.out.println("Welcome to");
  }
}

 

2) clsHello.java

 

public class clsHello extends absWelcome {
  // overriding the abstract method :
  public void printMessage() {
   System.out.println("Java Programming");
  }
}

 

3) Main.java

public class Main {
 public static void main(String[] args) {
  // object creation :
  clsHello obj = new clsHello();
  // using object to call methods :
  obj.printWelcome();
  obj.printMessage();
 }
}

 

 

Rewrite the program you create in Lab5A to use Interfaces instead of Abstract classes to implement
data hiding.
Your output should be the same as Lab5A
>sh -c javac -classpath
-type f -name '*.java')
3 java -classpath :targe
Welcome to
Java Programming
To Submit for Grading
1. Click the "More Options" vertical ellipse next to the Main.java file and choose Copy link
Main.java
Rename
Open tab
Copy link
2. In Moodle, click the link for this assignment
Week 4: Lab5B - Interfaces
Transcribed Image Text:Rewrite the program you create in Lab5A to use Interfaces instead of Abstract classes to implement data hiding. Your output should be the same as Lab5A >sh -c javac -classpath -type f -name '*.java') 3 java -classpath :targe Welcome to Java Programming To Submit for Grading 1. Click the "More Options" vertical ellipse next to the Main.java file and choose Copy link Main.java Rename Open tab Copy link 2. In Moodle, click the link for this assignment Week 4: Lab5B - Interfaces
Expert Solution
Step 1

An interface in Java is a blueprint of a class.

The following are the properties of an interface:

  • We cannot instantiate an interface.
  • It does not contain any constructors.
  • All of the methods in an interface are abstract.
  • Interface attributes must be declared both static and final.
  • An interface is implemented by a class.
  • A class must implement all the methods of an interface. If it does not provide method bodies for all functions, then the class must be declared abstract.

 

The purpose of the interface:

  • Java doesn’t support multiple inheritance. However, using interfaces, we can achieve multiple inheritance.
  • Loose-Coupling: We define the method separately and the signature separately.

 

It provides the way for total abstraction. Abstraction is an OOP concept that hides the background details. It shows only those pieces of information to the user which are most relevant for that specific process.

steps

Step by step

Solved in 5 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY