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
/** | |
* Define Dog class using supertype Animal | |
* Use safeguard annotation. | |
*/ | |
class App { | |
public static void main(String[] args) { | |
Dog d = new Dog(); | |
d.test(); // Dog | |
} |
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
<?php | |
/** | |
* Given the users $role and access $rights ... | |
* Check if Mike has admin rights and downgrade him | |
* Wrong approach: | |
* if ($is_admin && $can_edit_articles ... | |
*/ | |
$rights = (object) ["read"=>1, "write"=>2, "readwrite"=>16, "admin"=> 32]; | |
$role = (object) ["jim"=>96, "mike"=>32]; |
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
<?php | |
/** | |
* array_map() | |
* | |
* Round up array values | |
* Use array_map() with built-in ceil functions | |
* The result array $mapped will be [2, 3, 4] | |
*/ |
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
<?php | |
/** | |
* Define getMaxValue() method | |
* Use static syntax | |
*/ | |
class MyClass { | |
const MAX_VALUE = 100; |
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
<?php | |
/** | |
* Compose $m octal value using myFunc() recursively | |
* Use reminder and quontient values | |
* | |
* 97 (decimal) = 141 (octal) | |
* 97 % 8 => reminder 1 | |
* 12 % 8 => reminder 4 | |
* 1 % 8 => reminder 1 |
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
<?php | |
/** | |
* Define $output on multiple $lines | |
* Use Herodoc syntax. | |
* | |
* output = | |
* She said "This is John's test" | |
* on multiple rows | |
*/ |
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
/** | |
* Define a string s1 = "1" | |
* Define a number n1 = 2 | |
* Display the sum of s1 + n1 = 3 | |
* (convert the string to number) | |
*/ | |
class App { | |
public static void main(String[] args) { | |
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
/** | |
* Declare Number no as float 22.23 ... | |
* Use object's shortValue() method and ... | |
* Display no as 22 | |
*/ | |
class App { | |
public static void main(String[] args) { | |
/** |
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
/** | |
* Make a for-each loop and ... | |
* Output all names | |
*/ | |
class LearningApp { | |
public static void main(String[] args) { | |
String[] names = {"John", "Marry", "Ana"}; |
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
/** | |
* Declare showInfo() method ... | |
* The method should display "Cooper is 3 age old" ... | |
* The method must have no return type | |
*/ | |
class App { | |
public static void main(String[] args) { | |