Introduction to Git and GitHub

Git and GitHub are not the same things. Git is an open-source, version control tool created in 2005 by developers working on the Linux operating system while GitHub is a company founded in 2008 that…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Java Expected Output

Below are the questions to predict output which will help us to understand java concepts in detail and how things actually works.

Created list of 15 logical questions covering most of Java modules.

Find below answers for all above questions:

It will give compile time error as it is not allowed to declare parent Exception class before child exception.

This is because of string pooling where new keyword will point to both new location and variable. For more details:

true
false
false
false

A is having an instance of B and hence it will print line from B class printName() method. This is best example of runtime polymorphism or function overriding.

B

It will give compile time error as there is no printName() method available in class A to access. Neither it is a case of function overloading nor overriding.

static block get call on class load and non static block will get call at the time of instance creation using new keyword.

Static block before main() method
Static block after main() method
Non Static block before main() method
Non Static block after main() method

It follows BODMAS rule and resolve *(multiplication) before +(addition)

40John
John2020
John400

It will give compile time error as non static method can not get call inside static method. Using class instance variable we can access non static variable or method inside static method.

It will give compile time error as local static variables are not allowed.

null is not type of Object.

String method called

It will give compile time error as super() always needs to call at first line.

Finally
10

abc++ will increment value by one internally. But, internally abc variable will still have 4 value assigned.

For ++abc, the value already got incremented by one as part of abc++ and become 5. It will again get increment by one and become 6. Same value will get assign to abc as 6. At the end of the statement execution, 4 + 6 will become 10.

10

It will give compile time error as break statement always must come within loop.

It will print below output and override the previous value and override the the same with consider the

[A, B]

I hope you found out this article interesting and informative. Please share it with your friends to spread the knowledge.

You can follow me for upcoming blogs follow.
Thank you!

Add a comment

Related posts:

Best Speech activities for Toddlers

From the moment you realize that the baby is forming inside the stomach you’ll want to communicate any way you can. You’ll start by commenting when the baby is kicking, and before you know it you’ll…

FUNCTION IN PYTHON

The Python FUNCTION works as a function is every other programming language, though, differs in syntax. I will take you through a step-by-step process to write a function that accepts two values as…

Washington State Passes Blockchain Bill

Washington State officially passed State Bill 6065 that officially creates a Blockchain Working Group on March 10. This new working group is focused on creating a public/private partnership that…