Program 1:
class Q1{
public static void main(String args[]){
int a=4;
int b=8;
if((b-a--)>=a)
{
if((b+a)%2==1)
System.out.println(a*b);
else
System.out.println(b+a);
}
}
}
Program 2:
class Q2{
public static void main(String args[]){
int []A=new int[8];
int i=0;
for(i=-1;i<A.length-1;){
A[++i]=i;
}
String res=""+A[2]+(4%2)+(5%2)+i;
System.out.print(res);
}
}
Program 3
class A
{
int x=10;
}
class B extends A
{
int x=20;
}
public class Q3{
public static void main(String []args){
A a=new B();
System.out.print(a.x);
}
}
Program 4:
class Q4{
public static void main(String args[]){
int i=3;
int e=6;
int x=7;
String s="";
if((i+e)>=(i+x)){
i++;
s="gg";
e--;
}
else if((i+e+x)>=15){
x++;
s="wp";
}
System.out.print(x+s);
}
}
Program 5:
class Q5{
public static void main(String args[]){
String s1=new String("11001");
int d=Integer.parseInt(s1,2);
System.out.print(d);
}
}
Program 6:
class Base
{
Base()
{
System.out.println("Base");
}
Base(int n)
{
System.out.println("Base:"+n);
}
}
class Derive extends Base
{
Derive()
{
super(10);
System.out.println("Derive");
}
Derive(int n,int m)
{
super(n);
System.out.println("Derive:"+n+","+m);
}
}
class Q6{
public static void main(String args[]){
Derive D1=new Derive();
Derive D2=new Derive(40,50);
}
}
Answer Program 1:
Output
Answer Program 2:
Output
Answer Program 3:
Output
Reason: Derived class constructor first invokes the base class constructor.
Answer Program 4:
Output
Answer Program 5:
Output
Reason: The function parseInt(string , int) return decimal value according to specified string and base value.
Answer Program 6:
Output
Reason: Super Keyword is use to call the base class parameterized constructor through derive class according to specified parameter.
need an explanation for this answer? contact us directly to get an explanation for this answer