Java Training in Chennai – Basics – Learning – Part – II
This blog explains about Java Training in Chennai – Basics – Learning – Part – II . It is clearly discussed below .
We have already seen about few topics in the previous blog “Java Training in Chennai – Basics – Learning – Part – I “
_______________________________________________________________________
What will be the output of the following program?
class ReferencesAndObjects
{
public static void main(String s[])
{
Student st1 = new Student();
Student st2 = new Student();
st1 = st2;
st1.name = “Rajesh”;
st2.marks = 87;
st1.section = ‘C’;
System.out.println(“Print using st1 : ” + st1.name + ” ” + st1.marks + ” ” + st1.section);
System.out.println(“Print using st2 : ” + st2.name + ” ” + st2.marks + ” ” + st2.section);
}
}
class Student
{
String name;
int marks;
char section;
}
What will be the output of the following program?
class ReferencesAndObjects
{
public static void main(String s[])
{
Student st1 = new Student();
Student st2 = new Student();
st2 = st1;
st2 = new Student();
st1.name = “Rajesh”;
st2.marks = 87;
st1.section = ‘C’;
System.out.println(“Print using st1 : ” + st1.name + ” ” + st1.marks + ” ” + st1.section);
System.out.println(“Print using st2 : ” + st2.name + ” ” + st2.marks + ” ” + st2.section);
}
}
class Student
{
String name;
int marks;
char section;
}
class ReferencesAndObjects
{
public static void main(String s[])
{
Student st1 = new Student();
Student st2 = new Student();
st2 = st2;
st2 = new Student();
st1.name = “Rajesh”;
st2.marks = 87;
st1.section = ‘C’;
System.out.println(“Print using st1 : ” + st1.name + ” ” + st1.marks + ” ” + st1.section);
System.out.println(“Print using st2 : ” + st2.name + ” ” + st2.marks + ” ” + st2.section);
}
}
class Student
{
String name;
int marks;
char section;
}
public class ClassTwo
{
public static void main(String[] args)
{
ClassOne one = new ClassOne(‘Z’);
System.out.println(one.c);
}
}
class T {
int t = 20;
}
class Main {
public static void main(String args[]) {
T t1 = new T();
System.out.println(t1.t);
}
}
class T {
int t = 20;
T() {
t = 40;
}
}
class Main {
public static void main(String args[]) {
T t1 = new T();
System.out.println(t1.t);
}
}
class Test
{
static int a;
static
{
a = 4;
System.out.println (“inside static block\n”);
System.out.println (“a = ” + a);
}
Test()
{
System.out.println (“\ninside constructor\n”);
a = 10;
}
public static void func()
{
a = a + 1;
System.out.println (“a = ” + a);
}
public static void main(String[] args)
{
Test obj = new Test();
obj.func();
}
}
public class ClassB {
int x = 3;
public ClassB() {
System.out.print(new ClassA().method());
}
public ClassB(int i) {
System.out.print(i);
}
public int method(int i){
return x + i;
}
}
public class ClassA {
int y;
public ClassA() {}
public ClassA(ClassB classB) {
System.out.print(classB.method(1));
}
public int method(){
System.out.print(new ClassB(4).method(3));
return y;
}
public static void main(String[] args){
ClassA classA = new ClassA(new ClassB(new ClassB().method(2)));
}
}
Chapter 6: Exploring Methods
class Main {
public static void main(String args[]) {
System.out.println(fun());
}
int fun()
{
return 20;
}
}
public static void main(String args[]) {
String x = null;
giveMeAString(x);
System.out.println(x);
}
static void giveMeAString(String y)
{
y = “Payilagam”;
}
}
In the following method declaration, what is the return type?public static int myMethod(int count, double value) { return 4;}
In the following method declaration, what is the name of the method?public static void showMenu(String category) {}
In the following method declaration, how many formal parameters are there?public static double squareRoot(double value) { return 2.3;}
In the following method how many values are returned?public static void syncPhone(int idNumber) {}
______________________________________________________________________
REFERENCE :
https://payilagam.com/blogs/java-training-in-chennai-basics-learning-part-i
COURTESY :
www.proprofs.com, meritcampus.com, www.geeksforgeeks.org,
www.f5java.com, dzone.com, www.examveda.com, beingzero.in/,
scjptest.com, www.gocertify.com, web.cs.iastate.edu,
www.sanfoundry.com, https://codingpuzzles.com