

Java Abstraction and Exception
Presentation
•
Computers, Science
•
University
•
Practice Problem
•
Hard
Nishadi Ariyasinghe
Used 59+ times
FREE Resource
8 Slides • 6 Questions
1
Java Abstraction
G.N.P.Ariysinghe

2
Multiple Select
Which of the following can be used to achieve Abstraction? (Select all which is appropriate)
Abstract classes
Constructors
Interfaces
Enums
3
Abstract Classes and Methods
Data abstraction is the process of hiding certain details and showing only essential information to the user.
Abstract class: is a restricted class that cannot be used to create objects (to access it, it must be inherited from another class).
Abstract method: can only be used in an abstract class, and it does not have a body. The body is provided by the subclass (inherited from).
An abstract class can have both abstract and regular methods
4
Multiple Choice
abstract class Animal {
public abstract void animalSound();
public void sleep() {
System.out.println("Zzz");}}
What will be the output of the following code?
Animal myObj = new Animal();
Zzz
An error
myObj
animalSound
5
An error will be generated.
To access the abstract class, it must be inherited from another class.
6
Example
abstract class Animal {
public abstract void animalSound(); // Abstract method (does not have a body)
public void sleep() { // Regular method
System.out.println("Zzz");
}
}
class Pig extends Animal {
public void animalSound() {
System.out.println("The pig says: wee wee"); // The body of animalSound() is provided here
}
}
class Main {
public static void main(String[] args) {
Pig myPig = new Pig(); // Create a Pig object
myPig.animalSound();
myPig.sleep();
}
}
7
Multiple Choice
Which of these keywords are used to define an abstract class?
abst
abstract class
abstract
Abstract
8
Multiple Choice
If a class inheriting an abstract class does not define all of its function then it will be known as?
A simple class
A Static class
Abstract class
None of the mentioned
9
Any subclass of an abstract class must either implement all of the abstract method in the superclass or be itself declared abstract.
10
Multiple Choice
Which of these is not a correct statement?
Every class containing abstract method must be declared abstract
Abstract class defines only the structure of the class not its implementation
Abstract class can be initiated by new operator
Abstract class can be inherited
11
Abstract class cannot be directly initiated with new operator, Since abstract class does not contain any definition of implementation it is not possible to create an abstract object.
12
Multiple Choice
Which of these packages contains abstract keyword?
java.lang
java.util
java.io
java.system
13
class A {
public int i;
private int j;
}
class B extends A {
void display() {
super.j = super.i + 1;
System.out.println(super.i + " " + super.j);
}
}
class inheritance {
public static void main(String args[]) {
B obj = new B(); obj.i=1; obj.j=2; obj.display();
}
}
14
Class contains a private member variable j, this cannot be inherited by subclass B and does not have access to it.
$ javac inheritance.java
Exception in thread "main" java.lang.Error:
Unresolved compilation problem:
The field A.j is not visible
Java Abstraction
G.N.P.Ariysinghe

Show answer
Auto Play
Slide 1 / 14
SLIDE
Similar Resources on Wayground
11 questions
Changes in Matter Review
Presentation
•
6th - 8th Grade
12 questions
Introduction to C/C++ Programing
Presentation
•
KG - University
8 questions
Animales salvajes y domesticos
Presentation
•
KG
9 questions
first day
Presentation
•
University
11 questions
CAN and Comparative lesson
Presentation
•
University
11 questions
Ice Breaking
Presentation
•
Professional Development
10 questions
Lección sin título
Presentation
•
KG
10 questions
Diseño web_3ero BTI
Presentation
•
University
Popular Resources on Wayground
10 questions
Safety Day 2026 – Student Review
Quiz
•
9th Grade
21 questions
Continents and Oceans
Quiz
•
6th Grade
20 questions
Parts of Speech
Quiz
•
5th Grade
16 questions
Subject & Predicate
Quiz
•
5th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
12 questions
Map Skills
Quiz
•
3rd Grade
22 questions
Continents and Oceans
Quiz
•
5th Grade
15 questions
Rounding Decimals
Quiz
•
5th Grade
Discover more resources for Computers
20 questions
Disney Trivia
Quiz
•
University
10 questions
Spanish Greetings and Goodbyes!
Presentation
•
6th Grade - University
20 questions
Physical or Chemical Change/Phases
Quiz
•
8th Grade - University
39 questions
Unit 7 Key Terms
Quiz
•
11th Grade - University
25 questions
SER and Subject Pronouns
Quiz
•
8th Grade - University
38 questions
Unit 6 Key Terms
Quiz
•
11th Grade - University
19 questions
Key Concepts in Buddhism
Quiz
•
University
0 questions
Cell Domain Basic Review (Biology)
Quiz
•
University