Posts

Showing posts with the label OOP Exercises

An Example Of OOP Concept | Java Programs

Output: *** Class And Object Example *** Country Information: Name: Pakistan Provinces: 4 Population ( m ): 193.2 Click Here For  Java Online Compiler Solution: /** * * @author Alee Ahmed Kolachi */ class Country { String name ; int provinces ; float population ; public static void main ( String [] args ) { Country country1 = new Country (); country1 . name = "Pakistan" ; country1 . provinces = 4; country1 . population = 193.2f; //in millions System . out . println ( "*** Class And Object Example ***" + "\n" ); System . out . println ( "Country Information: " ); System . out . println ( "Name: " + country1 . name ); System . out . println ( "Provinces: " + country1 . provinces ); System . out . println ( "Population(m): " + country1 . population ...

A Very Common Example Of Class And Object | Java Programs

Output: *** Simple Class and Object Example *** Employee name : Alee Employee age : 19 ----------------------------- Employee name : Ahmed Employee age : 44 ----------------------------- Click Here For  Java Online Compiler Solution: /** * * @author Alee Ahmed Kolachi */ class Employee { String name ; int age ; public void showDetails () { System . out . println ( "Employee name : " + name ); System . out . println ( "Employee age : " + age ); System . out . println ( "-----------------------------" ); } public static void main ( String [] args ) { System . out . println ( "*** Simple Class and Object Example ***" + "\n" ); Employee employee = new Employee (); employee . name = "Alee" ; employee . age = 19; employee . showDetails (); Employee employee2 = new Employee (); ...