Question
Answer All the Questions Q1,Q2 and Q3 Q3. What will be the output of the following program? public class Staticdemo { static int x=10; public
Answer All the Questions Q1,Q2 and Q3
Q3. What will be the output of the following program?
public class Staticdemo { static int x=10; public static void main(string[]args) { Staticdemo t1 = new Staticdemo();
Staticdemo t2 = new Staticdemo();
t1.x = 45; System.out.print(t1.x+""); System.out.print(t2.x); } }
Q2. Which of the following lines of output are displayed by this program? class OuterClass{ String s1="java"; String s2 = "2"; public static void main(string []args){ OuterClass outer = new OuterClass(); System.out.println(outer.s2); } OuterClass(){ Inner inner = new Inner (); System.out.println(inner.s1); } class Inner{ String s1="Certification"; String s2="Exam";
Inner () { System.out.println(OuterClass.this.s1); System.out.println(this.s1); System.out.println(s2); } } }
Q1. Suppose you are designing an admission process that is part of a school program. The program only takes children aged between 6 and 15 years as well as weight between 20 and 50 kg into consideration. If you provide age outside the range, the program will cause an exception and show the message: Age is outside the range". If you provide weight outside the range, the program will cause another exception and show the message: "Weight is outside the range. Now, write down a program for the school using throw and throws keywords to implement the scenario. Q2. Which of the following lines of output are displayed by this program? class OuterClass { String si = "Java"; String s2 = "2"; | public static void main(String[] args) { OuterClass outer = new OuterClass(); System.out.println(outer.s2); } | OuterClass() { Inner inner = new Inner(); System.out.println(inner.s1); } | class Inner String 51 = "Certification"; String s2 = "Exam"; 1 Inner() { System.out.println(OuterClass.this.s1); System.out.println(this.s1); System.out.println(s2); } } }Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started