Computer Science, asked by nightwolf98, 6 months ago

Write a program in java of your own choice in which you can explain encapsulation and inheritance concepts, and in the context of that program write your
answer below that will explain
1. How encapsulation and inheritance was achieved in this program?
2. What are the benefits you get after implementing encapsulation and inheritance in this program?
3. What are the disadvantages if you will not use encapsulation and inheritance in this program?

Note: the program must be in java any IDE or netbeans and paste in comment the implementation!​

Answers

Answered by amankumar991123
2

Answer:

I am learning python now.

And I don't have a idea about java and other compiled languages.

If you have learned about python, so also help me in python.

Answered by Anonymous
3

pls \: follow \: me \\ or \: give \: me \: 5 \: thanks \\ pls \\  \\  \\ bts \: exo

Simple Example of Encapsulation in Java

//A Java class which is a fully encapsulated class.

//It has a private data member and getter and setter methods.

package com.javatpoint;

public class Student{

//private data member

private String name;

//getter method for name

public String getName(){

return name;

}

//setter method for name

public void setName(String name){

this.name=name

}

}

File: Test.java

//A Java class to test the encapsulated class.

package com.javatpoint;

class Test{

public static void main(String[] args){

//creating instance of the encapsulated class

Student s=new Student();

//setting value in the name member

s.setName("vijay");

//getting value of the name member

System.out.println(s.getName());

}

}

Output:

vijay

Attachments:
Similar questions