.Trashed-1742732428-Abstraction in Java - GeeksforGeeks
.Trashed-1742732428-Abstraction in Java - GeeksforGeeks
Abstraction in Java
Last Updated : 10 Jan, 2025
Example:
@Override
void turnOff() {
System.out.println("TV is turned OFF.");
}
}
We //
use cookies to ensuretoyoudemonstrate
Main class have the best browsing experience on our website. By using our site, you
abstraction
publicacknowledge that you have read and understood our Cookie Policy & Privacy Policy
class Main {
public static void main(String[] args) {
Got It !
Geeks remote = new TVRemote();
remote.turnOn();
remote.turnOff();
}
}
Output
TV is turned ON.
TV is turned OFF.
Consider
We use cookiesatoclassic
ensure you“shape” example,
have the best perhapsonused
browsing experience in a computer-aided
our website. By using our site, you
designacknowledge
system or thatgame
you havesimulation.
read and understood our Cookie
The base typePolicy
is &“shape”
Privacy Policy
and each
shape has a color, size, and so on. From this, specific types of shapes are
derived(inherited)-circle, square, triangle, and so on — each of which
may have additional characteristics and behaviors. For example, certain
shapes can be flipped. Some behaviors may be different, such as when
you want to calculate the area of a shape. The type hierarchy embodies
both the similarities and differences between the shapes.
Example 1:
double length;
double width;
System.out.println(s1.toString());
System.out.println(s2.toString());
}
}
Output
// Abstracted class
class Dog extends Animal {
public Dog(String name) {
super(name);
}
// Abstracted class
class Cat extends Animal {
public Cat(String name) {
super(name);
}
// Driver Class
public class Geeks {
// Main Function
public static void main(String[] args)
{
Animal myDog = new Dog("ABC");
Animal myCat = new Cat("XYZ");
myDog.makeSound();
myCat.makeSound();
}
}
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
Output
acknowledge that you have read and understood our Cookie Policy & Privacy Policy
ABC barks
XYZ meows
Interface
Output
Advantages of Abstraction
Disadvantages of Abstraction
FAQs
Benefits:
Encapsulation Abstraction
Encapsulation is a procedure
abstraction is a design-level
that takes place at the
process
implementation level
Example: Example: