please python
17.4 User-Defined Classes
An object combines variables and functions into a single entity. Objects get their variables and functions from classes. Classes are essentially templates for creating your objects. You can think of an object as a single data structure that contains data as well as functions. Functions of objects are called methods.
Problem
Create a variable, server_name, and assign a value to it inside `ServerClass` .
Code is Given Below:
=====================
class ServerClass:
#creating variable and assign a value to it
server_name="Apache Tomcat"
#creating object of ServerClass
myServer = ServerClass
#accessing variable of ServerClass
print(myServer.server_name)
Output:
==========
Code Snapshot:
=============
Explanation : Here first of all we define class named with ServerClass inside server class we define variable and assign "Apache Tomcat" to it
Then we create a object of ServerClass then we access value of varible stored in it
Get Answers For Free
Most questions answered within 1 hours.