Q:

Find Output of Java program - 2 (Mixed topics)

belongs to collection: Java find output programs

0

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);
	}
}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer Program 1:

Output

24

Answer Program 2:

Output

2017

Answer Program 3:

Output

10

Reason: Derived class constructor first invokes the base class constructor.

Answer Program 4:

Output

8wp

Answer Program 5:

Output

25

Reason: The function parseInt(string , int) return decimal value according to specified string and base value.

Answer Program 6:

Output

Base:10
Derive
Base:40
Derive:40,50

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

total answers (1)

Java find output programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java find output programs (if else) | set 2... >>
<< Find Output of Java program - 1 (Mixed topics)...