This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
class Phone: | |
username = "Kate" # public variable | |
__serial_number = "11.22.33" # private variable | |
__how_many_times_turned_on = 0 # private variable | |
def __init__(self): # constructor | |
print( "The Phone object was created" ) | |
self.__turn_on() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
class Phone: | |
number = "111-11-11" | |
def print_number(self): | |
print( "Phone number is: ", self.number ) | |
my_phone = Phone() | |
my_phone.print_number() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
class Phone: | |
username = "Kate" # public variable | |
__how_many_times_turned_on = 0 # private variable | |
def call(self): # public method | |
print( "Ring-ring!" ) | |
def __turn_on(self): # private method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
class Phone: | |
username = "Kate" # public variable | |
__serial_number = "11.22.33" # private variable | |
__how_many_times_turned_on = 0 # private variable | |
def call(self): # public method | |
print( "Ring-ring!" ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
class Phone: | |
def __init__(self, number): # magic method / inititalizer | |
print( "The Phone object was created" ) | |
self.number = number | |
def __lt__(self, other): # magic method / rich comparison | |
return self.number < other.number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class Contact | |
{ | |
private: | |
int mobile_number; // private variable | |
int home_number; // private variable | |
public: | |
Contact() // constructor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class Contact | |
{ | |
private: | |
int mobile_number; // private variable | |
int home_number; // private variable | |
public: | |
Contact() // constructor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class Contact | |
{ | |
private: | |
int mobile_number; // private variable | |
int home_number; // private variable | |
public: | |
Contact() // constructor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class Contact | |
{ | |
private: | |
int mobile_number; // private variable | |
int home_number; // private variable | |
public: | |
Contact() // constructor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "private_var.h" | |
#include <stdio.h> | |
int main() | |
{ | |
struct Contact * Tony; | |
Tony = create_contact(); | |
// printf( "Mobile number: %d\n", Tony->mobile_number); | |
// will cause compile time error | |
delete_contact( Tony ); |
OlderNewer