vildashnetwork02@gmail.com 654598457


CHAPTERELEVEN

Be focused and you will archive alot. choose your ON CSS

Explore more

history of html

Lorem ipsum dolor sit amet consectetur adipisicing elit. Hic odit rem dolorum molestiae fugit deserunt exercitationem recusandae, itaque ratione harum sit repellat dolor temporibus deleniti non voluptatem nostrum quas? Cumque veniam, molestias id natus pariatur dolores aut nemo iure facilis expedita, temporibus exercitationem ullam ex officiis reiciendis quaerat enim consequuntur.

Inheritance,Polymorphism and Encapsulation in Java

Explore the different cores of java programming below

Inheritance in Java

Inheritance is a fundamental concept in object-oriented programming that allows one class, known as the child or subclass, to inherit the properties and behaviors of another class, known as the parent or superclass.

Polymorphism in Java

Polymorphism enables objects to take on multiple forms, enhancing flexibility and scalability in Java programs.

Encapsulation in Java

Encapsulation is the practice of bundling data (fields) and methods (functions) that operate on the data into a single unit, typically a class.




Example 1: Basic Inheritance







// Parent class

class Animal {

String name;
                
void eat() {
System.out.println(name + " is eating.");
}
}
                
// Child class
class Dog extends Animal {
void bark() {
System.out.println(name + " is barking.");
}
}
                
public class Main {
public static void main(String[] args) {
 Dog dog = new Dog();
dog.name = "Buddy";
dog.eat(); // Inherited method
dog.bark(); // Method of Dog class
}
}      
Output:

Buddy is barking.
            





Example 2: Multilevel Inheritance




// Parent class
class Vehicle {
void start() {
System.out.println("Vehicle is starting.");
}
}
                    
// Child class
class Car extends Vehicle {
void drive() {
System.out.println("Car is driving.");
}
}
                    
// Grandchild class
class SportsCar extends Car {
void turbo() {
System.out.println("SportsCar turbo mode activated.");
}
}
                    
public class Main {
public static void main(String[] args) {
SportsCar sportsCar = new SportsCar();
sportsCar.start(); // Inherited from Vehicle
sportsCar.drive(); // Inherited from Car
sportsCar.turbo(); // Method of SportsCar
}
}  
Output:

SportsCar turbo mode activated.
                






Example 3: Method Overloading (Compile-time Polymorphism)



class Calculator {
int add(int a, int b) {
return a + b;
}
                    
double add(double a, double b) {
return a + b;
}
                    
int add(int a, int b, int c) {
return a + b + c;
}
}
                    
public class Main {
public static void main(String[] args) {
Calculator calc = new Calculator();
System.out.println("Sum of 2 integers: " + calc.add(5, 10));
System.out.println("Sum of 2 doubles: " + calc.add(5.5, 2.3));
System.out.println("Sum of 3 integers: " + calc.add(1, 2, 3));
}
}
Output:
Sum of 2 integers:  15

Sum of 2 doubles: 7.8

Sum of 3 integers: 6
                





Example 4: Method Overriding (Runtime Polymorphism)



// Parent class
class Animal {
void makeSound() {
System.out.println("Some generic animal sound.");
}
}
                    
// Child class
class Dog extends Animal {
@Override  void makeSound() {

System.out.println("Dog barks.");
}

}
                    
// Child class
class Cat extends Animal {
@Override
void makeSound() {
System.out.println("Cat meows.");
}
}
                    
public class Main {
public static void main(String[] args) {
Animal myAnimal;

myAnimal = new Dog();
myAnimal.makeSound(); // Output: Dog barks.
                    
myAnimal = new Cat();
myAnimal.makeSound(); // Output: Cat meows.
}
}
                
        
Output:

Dog barks.
Cat meows.
            





Example 5: Using Getters and Setters (Encapsulation in Java)



class BankAccount {
private double balance;
                    
// Getter method
public double getBalance() {
return balance;
}
                    
// Setter method
public void setBalance(double balance) {
if (balance >= 0) {
this.balance = balance;
} else {
System.out.println("Balance cannot be negative.");
}
}
}
                    
public class Main {
public static void main(String[] args) {
BankAccount account = new BankAccount();
account.setBalance(500.00);
System.out.println("Account balance: $" + account.getBalance());
}
                    }
                
Output:

Is Java fun? 1






Example 6: Hiding Sensitive Data (Encapsulation in Java)



class Employee {
private String name;
private double salary;
                    
public String getName() {
return name;
}
                    
public void setName(String name) {
this.name = name;
}
                    
public double getSalary() {
return salary;
}
                    
public void setSalary(double salary) {
if (salary > 0) {

this.salary = salary;
} else {
System.out.println("Salary must be positive.");
}
}
}
                    
public class Main {
public static void main(String[] args) {
Employee emp = new Employee();
emp.setName("John Doe");
emp.setSalary(55000);
System.out.println("Employee: " + emp.getName());
System.out.println("Salary: $" + emp.getSalary());
}}
                
Output:
Salary: $55000 
               

TESTIMONIES

vildash network team has had alot of impact on others but here are the vildash network team testimonies and expirience while working with the team

favour

am a graphic designer for vildash. when i first join vildash my first dream was programing but i got to know that programing neeeds alot of patients and coding but now my dream is more on the front end so i design graphics and make amazing ui/ux design. vildash is and amazing and great team

MR BK

when i first joined vildash my first vision was that i wanted to upgrade my skills and i really wanted to take a longer time but with vildash i got to know the fastest way in other to be perfect in programing and building amazing projects with ease

MR ENGEBEL

i was nothing in programing and i was discouraged cause i discovered that all programers had laptops but i didnt have and i got discouragecd cause, i thought i didnt evn have that chance to be a programer because of that but when i join vildash i got to know that its not just about the laptop its about the determination and if i have the determination i can archive. and i got to start programing with just my android phone and just like that am gradually getting there

MR LEWIS

vildash network has given me a chance to become a programmer, i now do thinks i didnt know i would be able to do, i now know tyhat i dont have to get distracted i need to stay focused and archive my goals

MR BROSKII

am a good programmer and i didnt have a team but i never knew how working with a team fills like but vildash network has given me the best expirience of how that feel, now i can boast of working with a team and the best team. it feels really greate cause with vildashi have to know that i can use my skills to do more than i dreamed of.

Events

you can now connect and text other users from our database. you just neeed to click bellow to message them

  • connect with programmers

    you can ask for help form them and also you can solve problems with them.

    click here to start chat
  • capabilities

    you can send and recieve messagies. you can send emojies, images, and you can also chat privately with a memeber and you can see when a member is online or offline

    click here to start chat

OUR CODE EDITORS

WE HAVE CODE EDITORS FOR LANGUAGES LIKE C, C#, C++, HTML, CSS, javascript, JAVA VISUAL BASIC

WHAT WE ARE OUT TO DO

We dont just teach you to code we teach you to code and build amazing systems.we are group of expert who wants to promote our field of studies