I've just read in an OCA-Book (Oracle Certified Associate), that:  "Some casts exceptions can be detected as errors at compile-time, but others can only be detected at runtime".  Now I am trying to find an example for both cases: compile-time and runtime.  Consider the following class structure:  class A {}  class B extends A {}  class C extends B {}   The following cast  Object o = new C(); B b = (B) o;   is correct. So the code would run without a ClassCastException.  The cast  Object o = new B(); C c = (C) o;   is wrong. The Object o is at least of the type B; so it could be cast to B or A.  But could be this detected at runtime or compile-time? I would guess at compile-time?! Or does the compiler knows only the type of the reference, not of the object (in the memory) itselfs? If this is true, the compiler could not decide if the cast is correct or not at compile-time.  Thank you for your help!
Upcasting is allowed in Java, however downcasting gives a compile error.   The compile error can be removed by adding a cast but would anyway break at the runtime.   In this case why Java allows downcasting if it cannot be executed at the runtime? Is there any practical use for this concept?   public class demo {   public static void main(String a[]) {       B b = (B) new A(); // compiles with the cast,                           // but runtime exception - java.lang.ClassCastException   } }  class A {   public void draw() {     System.out.println("1");   }    public void draw1() {     System.out.println("2");   } }  class B extends A {   public void draw() {     System.out.println("3");   }   public void draw2() {     System.out.println("4");   } }
"Dummy Output" No sound in Ubuntu 16.04 None of the HDMI output are working, all saying "dummy output", it was working yesterday, but when I use the headphones it became soundless, with or without the headphones.  Thank you already! How to convert an "object" into a function in JavaScript? JavaScript allows functions to be treated as objects--if you first define a variable as a function, you can subsequently add properties to that function.  How do you do the reverse, and add a function to an "object"?  This works:  var foo = function() { return 1; }; foo.baz = "qqqq";   At this point, foo() calls the function, and foo.baz has the value "qqqq".  However, if you do the property assignment part first, how do you subsequently assign a function to the variable?  var bar = { baz: "qqqq" };   What can I do now to arrange for bar.baz to have the value "qqqq" and bar() to call the function? What is the number of strings at size $n$ that is constructed from ${a,b,c,d}$ and there is an even num of $a$ What is the number of strings at size $n$ that is constructed from ${a,b,c,d}$ and there is an even num of $a$?  I have tried to answer it as recursion formula in the following logic:  In order to build $ A(n) $, I will split into several cases:   if the string starts with $a$, then I will need another $a$ to make an even number of $a's$. so we get $aa[A(n-2)]$ meaning 2 $a's$ at the start + a valid string at the size of $n-2$. if it starts with $b,c,d$ we get $b[A(n-1)]$ + $c[A(n-1)]$ +$d[A(n-1)]$, meaning a one of the letters + a valid string at the size of $n-1$.   So we will get a recursion formula that looks like that:  $A(n) = A(n-2) + 3A(n-1)$  I'm not 100% on my answer, am I right to approach it in that direction? Given a compact Hausdorff space $X$, if $a \in X$ is a $G_\delta$ singleton (i.e., $\{ a \}$ is a $G_\delta$ set), then there is a countable local base at $a$.   The point $a$ can be written as countable intersection of open sets let's call $U_{n}$.  How can I use the compactness? What is the next step for proof? Could you give me hint please? Let $f(x) = x^2 \sin{\frac{1}{x}}$ for $x\neq 0$ and $f(0) =0$. (a) Use the basic properties of the derivative, and the Chain Rule to show that $f$ is differentiable at each $a\neq 0$ and calculate $f'(a)$. You may use without proof that $\sin$ is differentiable and that $\sin' =\cos$.  Not even sure what this is asking.  (b) Show that $f$ is differentiable at $0$ and that $f'(0) =0$.  $\frac {f(x)-f(0)}{x-0} \to \lim_{x \to 0} x \sin(1/x)$. $x \sin(1/x) \leq |x|$ and $\lim_{x \to 0} |x|=0$. Thus $f(x)$ is differentiable at $0$; moreover $f^{'}(0)=0$.  (c) Show that $f'$ is not continuous at $0$.  $f{'}(x)=x^{2} \cos(1/x) (-x^{-2}) + 2x \sin (1/x)$. In pieces: $\lim_{x \to 0} \cos (1/x)$. $f^{'}(0-)$ nor $f{'}(0+)$ exists as $x \to 0$ $f^{'}(x)$ oscillates infinity between $-1$ and $1$ with ever increase frequency as $x \rightarrow 0$ for any $p&gt;0$ $[-p,0]$, $[-p,p]$ or $[0,p]$ $f$ is not continuous. Question: How to show more rigorously? How to make an embedded question from "What time is it?" If the original question is "What time is it?" and I want to communicate it to another person, are these Embedded Questions OK?        I don't know what time is it.       or        I didn't know what time was it. (if communicated later) Selecting a security team that includes at most one of the oldest man or oldest woman A security company consists of $7$ men and $6$ women. Determine the number of ways to form the night shift team of $3$ men and $3$ women if it can include at most one of the oldest man or oldest woman.  I know the first step is to pick $3$ from each group which is   $_6C_3 \cdot _7C_3 $  but I am not sure how to account for the "include at most one of the oldest man or oldest woman"   The answer is $_6C_3 \cdot _7C_3 + _6C_3 \cdot _5C_3 + _6C_2 \cdot _5C_3 $  Also, how do I account for it in my calculations if I want to include the oldest man and oldest woman from the group? Why is this regex allowing a caret? How to check if a number is a power of 2 Today I needed a simple algorithm for checking if a number is a power of 2.  The algorithm needs to be:   Simple Correct for any ulong value.   I came up with this simple algorithm:  private bool IsPowerOfTwo(ulong number) {     if (number == 0)         return false;      for (ulong power = 1; power &gt; 0; power = power &lt;&lt; 1)     {         // This for loop used shifting for powers of 2, meaning         // that the value will become 0 after the last shift         // (from binary 1000...0000 to 0000...0000) then, the 'for'         // loop will break out.          if (power == number)             return true;         if (power &gt; number)             return false;     }     return false; }   But then I thought, how about checking if log2 x is an exactly round number? But when I checked for 2^63+1, Math.Log returned exactly 63 because of rounding. So I checked if 2 to the power 63 is equal to the original number - and it is, because the calculation is done in doubles and not in exact numbers:  private bool IsPowerOfTwo_2(ulong number) {     double log = Math.Log(number, 2);     double pow = Math.Pow(2, Math.Round(log));     return pow == number; }   This returned true for the given wrong value: 9223372036854775809.  Is there a better algorithm? Adding admin-ajax.php to the frontend. Good or bad idea? I love admin-ajax.php. But I hate having to localize in order to point frontend scripts to it, and I wish there was an equivalent, easy-to-find file for themes. (It also just bothers me to see frontend requests go through "/wp-admin/". No practical reason, just looks ugly IMO.)  So I've simply copied admin-ajax.php to the root dir at "/ajax.php", adjusted the include paths and removed the WP_ADMIN constant definition. Seems to work like gangbusters (I can now just direct all my frontend AJAX requests to /ajax.php! And I can still use the normal wp_ajax hooks in my plugins!).  But is this safe? What might go wrong? Since this isn't built into core, I assume there's a good reason as to why not. But looking through the code, I can't see any immediate problems.   You're smart--tell me if this approach is crazy. Or if there's a simpler method that I'm overlooking. Iterating each character in a string using Python No Dropbox top panel icon since update to 18.04 What are the most important things I need to do to encourage Google Sitelinks? My website used to have sitelinks and now it doesn't. It's very possible that it's due to changing the website to a sidebar design instead of having an "interstitial" type landing page which limited the number of choices, but I'm not sure.  Here is how sitelinks might look for a site:    What are some things that I can do to improve my chances of getting sitelinks? When I go to any github.com page in Chrome, I get a big ugly error:  You attempted to reach github.com, but the server presented a certificate issued by an entity that is not trusted by your computer's operating system. This may mean that the server has generated its own security credentials, which Chrome cannot rely on for identity information, or an attacker may be trying to intercept your communications. You cannot proceed because the website operator has requested heightened security for this domain.  The same thing happens (in Chrome and with curl) when I go to  too. This strange problem started about a week and a half ago. Here's what I see when I click the broken lock icon in the address bar:   But gist.github.com works just fine:   It doesn't work with curl either:  Everything works fine in Firefox. How can I fix my root CA problem? Here's what it looks like in Firefox:   Update: I noticed that the first certificate in the chain is different in my broken Chrome/Safari as compared to Chrome on my other computer.   (There's no nasty red X anymore because I trusted it in Safari.) See how the issuers are different? What can I make of that? How can I disable the "Welcome, Name!" banner notification for Game Center? If you view the Earth from far enough away can you observe its past? How to reduce AWS EBS root volume size? Is it safe to use a voltage divider for Arduino and DC motor controller? Brackets in if condition: why am I getting syntax errors without whitespace? Notify instantly when a currently viewed post is deleted At the moment SE shows us current voting results, a notification for new answers and comments, etc., instantly. However, it doesn't show us when a post is deleted.  Please notify us also when a post is deleted. Then I don't have to type a (long) comment, only to notice the post got deleted in the meantime.